Skip to content

Build your personal knowledge base with Trilium Notes

test(share): cover a heading spanning lines on a rendered page

Elian Doranc3f00b941bf4
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index d3acc5cd5d..6fe05ee0cd 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -341,6 +341,27 @@ describe("content_renderer", () => {
expect(page.querySelector(".navigation .next")?.text).toBe("Second");
});
+ it("anchors a heading spanning lines and lists it in the table of contents", () => {
+ const shareRootNote = buildShareNote({
+ id: shareRoot.SHARE_ROOT_NOTE_ID,
+ children: [{
+ id: "multilineHeadings",
+ content: `<h2>First</h2><p>a</p><h2>Spans\n two lines</h2><p>b</p>`
+ }]
+ });
+
+ const page = parse(String(renderNoteContent(shareRootNote.getChildNotes()[0])));
+
+ expect(page.querySelector("#content h2:last-of-type .toc-anchor")?.id)
+ .toBe("spans-two-lines");
+ expect(page.querySelectorAll("#toc a").map((link) => [
+ link.getAttribute("href"), link.text.trim()
+ ])).toStrictEqual([
+ [ "#first", "First" ],
+ [ "#spans-two-lines", "Spans two lines" ]
+ ]);
+ });
+
it("keeps the alt text of an image on the page", () => {
const shareRootNote = buildShareNote({
id: shareRoot.SHARE_ROOT_NOTE_ID,