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(text): cover markdown export/import of collapsed list items
Elian Doranfab96d5d006d
diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.tsindex e0cbb66fe2..55cf49cdb6 100644--- a/packages/trilium-core/src/services/export/markdown.spec.ts+++ b/packages/trilium-core/src/services/export/markdown.spec.ts@@ -445,6 +445,32 @@ describe("Markdown export", () => {expect(markdownExportService.toMarkdown(html)).toBe(expected);});+ it("drops data-trilium-collapsed but keeps the collapsed item's children as bullets", () => {+ // Collapsing is editor-only UI state (the nested items live in the content, hidden via+ // CSS), and Markdown has no syntax for it — so the attribute is dropped on export while+ // the nested structure still round-trips as ordinary bullets.+ const html = trimIndentation/*html*/`\+ <ul>+ <li data-trilium-collapsed="true">+ Parent+ <ul>+ <li>+ Child+ </li>+ </ul>+ </li>+ <li>+ Sibling+ </li>+ </ul>+ `;+ const expected = trimIndentation`\+ * Parent+ * Child+ * Sibling`;+ expect(markdownExportService.toMarkdown(html)).toBe(expected);+ });+it("exports jQuery code in table properly", () => {const html = trimIndentation`\<figure class="table">diff --git a/packages/trilium-core/src/services/import/single.spec.ts b/packages/trilium-core/src/services/import/single.spec.tsindex aa2e619aea..0ce769ceb5 100644--- a/packages/trilium-core/src/services/import/single.spec.ts+++ b/packages/trilium-core/src/services/import/single.spec.ts@@ -12,12 +12,15 @@ import stripBom from "strip-bom";import { getContext } from "../context.js";const scriptDir = dirname(fileURLToPath(import.meta.url));-async function testImport(fileName: string, mimetype: string, bufferOverride?: Buffer) {+async function testImport(fileName: string, mimetype: string, bufferOverride?: Buffer, extraOptions?: Record<string, unknown>) {const buffer = bufferOverride ?? fs.readFileSync(`${scriptDir}/samples/${fileName}`);- const taskContext = TaskContext.getInstance("import-mdx", "importNotes", {+ // getInstance caches by task id, so a caller needing distinct options (e.g. safeImport) must+ // use a distinct id rather than reusing the shared "import-mdx" context.+ const taskContext = TaskContext.getInstance(extraOptions ? `import-${fileName}` : "import-mdx", "importNotes", {textImportedAsText: true,codeImportedAsCode: true,- spreadsheetImportedAsSpreadsheet: true+ spreadsheetImportedAsSpreadsheet: true,+ ...extraOptions});return new Promise<{ buffer: Buffer; importedNote: BNote }>((resolve, reject) => {@@ -76,6 +79,18 @@ describe("processNoteContent", () => {expect(importedNote.getContent().toString().substring(0, 5)).toEqual("<html");});+ it("safe import preserves data-trilium-collapsed on list items", async () => {+ const html = `<ul><li data-trilium-collapsed="true">Parent<ul><li>Child</li></ul></li></ul>`;+ const { importedNote } = await testImport("collapsed-list.html", "text/html", Buffer.from(html), { safeImport: true });++ expect(importedNote.mime).toBe("text/html");+ // safeImport runs the content through the sanitizer; data-* attributes are whitelisted, so+ // the collapsed-state flag survives along with the nested item.+ const content = importedNote.getContent().toString();+ expect(content).toContain(`data-trilium-collapsed="true"`);+ expect(content).toContain("Child");+ });+it("supports code note with UTF-16", async () => {const { importedNote, buffer } = await testImport("UTF-16LE Code Note.json", "application/json");expect(importedNote.mime).toBe("application/json");