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(markdown export): keep tables with admonitions as raw HTML
Elian Doranca620986e26f
diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.tsindex 4a37943c75..2f5bf96745 100644--- a/packages/trilium-core/src/services/export/markdown.spec.ts+++ b/packages/trilium-core/src/services/export/markdown.spec.ts@@ -566,6 +566,54 @@ describe("Markdown export", () => {expect(markdownExportService.toMarkdown(html)).toBe(expected);});+ // Admonitions are block content, and GFM table cells can only hold inline+ // content. Flattening the admonition into a cell produces unrenderable+ // `> [!NOTE]<br>...` noise, so a table containing one is kept as raw HTML to+ // degrade gracefully and round-trip faithfully.+ it("keeps a table containing an admonition as HTML", () => {+ const html = trimIndentation/*html*/`\+ <figure class="table">+ <table>+ <thead>+ <tr>+ <th>Hello</th>+ <th>world</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td>This is a table</td>+ <td></td>+ </tr>+ <tr>+ <td><aside class="admonition note"><p>With an admonition inside it</p></aside></td>+ <td></td>+ </tr>+ </tbody>+ </table>+ </figure>+ `;+ const expected = `<table>+ <thead>+ <tr>+ <th>Hello</th>+ <th>world</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td>This is a table</td>+ <td></td>+ </tr>+ <tr>+ <td><aside class="admonition note"><p>With an admonition inside it</p></aside></td>+ <td></td>+ </tr>+ </tbody>+</table>`;+ expect(markdownExportService.toMarkdown(html)).toBe(expected);+ });+it("preserves superscript and subscript", () => {const html = /*html*/`<p>Hello <sup><strong>superscript</strong></sup> <sub><strong>subscript</strong></sub></p>`;const expected = `Hello <sup><strong>superscript</strong></sup> <sub><strong>subscript</strong></sub>`;diff --git a/packages/turndown-plugin-gfm/src/lib/tables.ts b/packages/turndown-plugin-gfm/src/lib/tables.tsindex 35cc061c7a..ad569dd044 100644--- a/packages/turndown-plugin-gfm/src/lib/tables.ts+++ b/packages/turndown-plugin-gfm/src/lib/tables.ts@@ -201,7 +201,11 @@ const tableShouldBeHtml = (tableNode: any, options: TurnishOptions | null): bool'H6','HR','BLOCKQUOTE',- 'PRE'+ 'PRE',+ // Admonitions render as <aside class="admonition">. Like the other block-level+ // tags above, they can't live inside a GFM table cell — flattening one there+ // yields unrenderable `> [!NOTE]<br>...` — so keep the whole table as raw HTML.+ 'ASIDE'];// In general we should leave as HTML tables that include other tables. The