Skip to content

Commit 623da7e

Browse files
committed
fix(share): syntax highlighting doesn't unescape properly (closes #7783)
1 parent 84b3d6d commit 623da7e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

apps/server/src/share/content_renderer.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ describe("content_renderer", () => {
8181
<p>After</p>
8282
`);
8383
});
84+
85+
it("handles syntax highlight for code blocks with escaped syntax", () => {
86+
const note = buildShareNote({
87+
id: "note",
88+
content: trimIndentation`\
89+
<h2>
90+
Defining the options
91+
</h2>
92+
<pre>
93+
<code class="language-text-x-trilium-auto">&lt;t t-name="module.SectionWidthOption"&gt;
94+
&lt;BuilderRow label.translate="Section Width"&gt;
95+
&lt;/BuilderRow&gt;
96+
&lt;/t&gt;</code>
97+
</pre>
98+
`
99+
});
100+
const result = getContent(note);
101+
expect(result.content).toStrictEqual(trimIndentation`\
102+
<h2>
103+
Defining the options
104+
</h2>
105+
<pre>
106+
<code class="language-text-x-trilium-auto hljs"><span class="hljs-tag">&lt;<span class="hljs-name">t</span> <span class="hljs-attr">t-name</span>=<span class="hljs-string">&quot;module.SectionWidthOption&quot;</span>&gt;</span>
107+
<span class="hljs-tag">&lt;<span class="hljs-name">BuilderRow</span> <span class="hljs-attr">label.translate</span>=<span class="hljs-string">&quot;Section Width&quot;</span>&gt;</span>
108+
<span class="hljs-tag">&lt;/<span class="hljs-name">BuilderRow</span>&gt;</span>
109+
<span class="hljs-tag">&lt;/<span class="hljs-name">t</span>&gt;</span></code>
110+
</pre>
111+
`)
112+
});
84113
});
85114

86115
describe("renderCode", () => {

apps/server/src/share/content_renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function renderText(result: Result, note: SNote | BNote) {
330330
continue;
331331
}
332332

333-
const highlightResult = highlightAuto(codeEl.innerText);
333+
const highlightResult = highlightAuto(codeEl.text);
334334
codeEl.innerHTML = highlightResult.value;
335335
codeEl.classList.add("hljs");
336336
}

0 commit comments

Comments
 (0)