feat(view,tests): query blocks stay code in text the agent did not write

This commit is contained in:
hh committed 2026-10-13 01:23:49 +02:00
1 parent 43d1e1a4a3
commit 91699a382e
5 files changed
+66 -4

No files matched your search

+15 -3
View File
@@ -1,5 +1,6 @@
import type { App, Component } from "obsidian";
import { MarkdownRenderer, Platform } from "obsidian";
import { MarkdownPreviewRenderer, MarkdownRenderer, Platform } from "obsidian";
import { inertFences } from "$lib/panel/fences";
import type { PanelHost } from "$lib/panel/host";
export interface HostOptions {
@@ -12,17 +13,28 @@ export interface HostOptions {
sourcePath: () => string;
}
const QUERY_LANGUAGES = new Set(["tasks", "dataview", "dataviewjs", "query"]);
function runs(language: string): boolean {
const registered = (
MarkdownPreviewRenderer as unknown as {
codeBlockPostProcessors?: Record<string, unknown>;
}
).codeBlockPostProcessors;
return QUERY_LANGUAGES.has(language) || language in (registered ?? {});
}
// The Obsidian side of the panel: markdown through the app's own renderer,
// [[links]] opened in place, a conversation's note opened by its binding.
export function obsidianHost(options: HostOptions): PanelHost {
const { app, component } = options;
return {
markdown(node, text) {
markdown(node, text, { inert = false } = {}) {
let alive = true;
const staging = document.createElement("div");
MarkdownRenderer.render(
app,
text,
inert ? inertFences(text, runs) : text,
staging,
options.sourcePath(),
component