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
test(server/share): included text notes
Elian Doran8b5e53e5792a
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.tsindex 363b743907..137d85c97e 100644--- a/apps/server/src/share/content_renderer.spec.ts+++ b/apps/server/src/share/content_renderer.spec.ts@@ -1,7 +1,7 @@import { describe, it, expect } from "vitest";import { getContent, renderCode, renderText, type Result } from "./content_renderer.js";import { trimIndentation } from "@triliumnext/commons";-import { buildShareNote } from "../test/shaca_mocking.js";+import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js";describe("content_renderer", () => {it("Reports protected notes not being renderable", () => {@@ -28,6 +28,29 @@ describe("content_renderer", () => {const result = getContent(note);expect(result.content).toStrictEqual(content);});++ it("renders included notes", () => {+ buildShareNotes([+ { id: "subnote1", content: `<p>Foo</p><div>Bar</div>` },+ { id: "subnote2", content: `<strong>Baz</strong>` }+ ]);+ const note = buildShareNote({+ id: "note1",+ content: trimIndentation`\+ <p>Before</p>+ <section class="include-note" data-note-id="subnote1" data-box-size="small"> </section>+ <section class="include-note" data-note-id="subnote2" data-box-size="small"> </section>+ <p>After</p>+ `+ });+ const result = getContent(note);+ expect(result.content).toStrictEqual(trimIndentation`\+ <p>Before</p>+ <p>Foo</p><div>Bar</div>+ <strong>Baz</strong>+ <p>After</p>+ `);+ });});describe("renderCode", () => {diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex 253c43b39d..2371622006 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -80,7 +80,7 @@ export function renderText(result: Result, note: SNote) {if (typeof includedResult.content !== "string") continue;const includedDocument = new JSDOM(includedResult.content).window.document;- includeNoteEl.replaceWith(includedDocument.body);+ includeNoteEl.replaceWith(...includedDocument.body.childNodes);}result.isEmpty = document.body.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0;diff --git a/apps/server/src/test/shaca_mocking.ts b/apps/server/src/test/shaca_mocking.tsindex 022ee999ad..af02394a04 100644--- a/apps/server/src/test/shaca_mocking.ts+++ b/apps/server/src/test/shaca_mocking.ts@@ -10,6 +10,7 @@ interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {id?: string | undefined;title?: string;content?: string | Buffer<ArrayBufferLike>;+ children?: NoteDefinition[];isProtected?: boolean;}@@ -59,6 +60,15 @@ export function buildShareNote(noteDef: NoteDefinition) {};}+ // Handle children.+ if (noteDef.children) {+ for (const childDef of noteDef.children) {+ const childNote = buildShareNote(childDef);++ // TODO: Create corresponding SBranch.+ }+ }+// Handle labels & relationslet position = 0;for (const [ key, value ] of Object.entries(noteDef)) {