Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): keep the block ID of a diagram shown in a read-only box
Elian Doran38a1ff558c51
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsxindex 2433ec3a3c..2e6d05217d 100644--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx@@ -446,8 +446,10 @@ describe("ReadOnlyText embedded notes", () => {describe("ReadOnlyText Mermaid diagrams", () => {const html = `<pre data-box-size="small" data-display-mode="source" data-hide-title="true"`- + ` style="--include-note-height:12em;"><code class="language-mermaid">graph TD;</code></pre>`- + `<pre><code class="language-mermaid" data-trilium-display-mode="split">graph LR;</code></pre>`+ + ` data-trilium-block-id="b1" style="--include-note-height:12em;">`+ + `<code class="language-mermaid">graph TD;</code></pre>`+ + `<pre><code class="language-mermaid" data-trilium-display-mode="split"`+ + ` data-trilium-block-id="b2">graph LR;</code></pre>`+ `<pre><code class="language-javascript">let a;</code></pre>`;afterEach(() => {@@ -493,13 +495,13 @@ describe("ReadOnlyText Mermaid diagrams", () => {{language: "mermaid", source: "graph TD;", isReadOnly: true, boxSize: "small",options: { isFocused: false }, isInPage: true,- data: { boxSize: "small", displayMode: "source", hideTitle: "true" },+ data: { boxSize: "small", displayMode: "source", hideTitle: "true", triliumBlockId: "b1" },height: "12em"},{language: "mermaid", source: "graph LR;", isReadOnly: true, boxSize: "medium",options: { isFocused: false }, isInPage: true,- data: { boxSize: "medium", hideTitle: "true" },+ data: { boxSize: "medium", hideTitle: "true", triliumBlockId: "b2" },height: ""}]);diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsxindex ee4c811b83..d3e50290a3 100644--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx@@ -261,6 +261,11 @@ function applySourceEmbeds(container: HTMLDivElement) {figure.dataset.displayMode = displayMode;}figure.dataset.hideTitle = "true";+ // Diagrams saved before the embed keep their block ID on the `<code>`.+ const blockId = pre.dataset.triliumBlockId ?? code.dataset.triliumBlockId;+ if (blockId) {+ figure.dataset.triliumBlockId = blockId;+ }const style = pre.getAttribute("style");if (style) {figure.setAttribute("style", style);