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): wrap imported tables in figure.table for read-only rendering (closes #10270)
Elian Doran05802b359c57
diff --git a/packages/commons/src/lib/markdown_renderer.spec.ts b/packages/commons/src/lib/markdown_renderer.spec.tsindex 4877124107..c4a0dddf5b 100644--- a/packages/commons/src/lib/markdown_renderer.spec.ts+++ b/packages/commons/src/lib/markdown_renderer.spec.ts@@ -321,6 +321,19 @@ describe("renderToHtml", () => {});});+ describe("tables (CustomMarkdownRenderer.table)", () => {+ it("wraps a table in <figure class=\"table\"> to match CKEditor's structure (#10270)", () => {+ const html = render("| a | b |\n|---|---|\n| c | d |");+ expect(html).toContain('<figure class="table">');+ expect(html).toContain("</figure>");+ // The wrapper hugs the table with no stray whitespace between them.+ expect(html).toContain('<figure class="table"><table>');+ expect(html).toContain("</table></figure>");+ expect(html).toContain("<th>a</th>");+ expect(html).toContain("<td>c</td>");+ });+ });+describe("blockquotes / admonitions (CustomMarkdownRenderer.blockquote)", () => {it("renders a [!NOTE] admonition", () => {expect(render("> [!NOTE]\n> body")).toBe('<aside class="admonition note"><p>body</p></aside>');diff --git a/packages/commons/src/lib/markdown_renderer.ts b/packages/commons/src/lib/markdown_renderer.tsindex 9dcecaaedb..f5d0675402 100644--- a/packages/commons/src/lib/markdown_renderer.ts+++ b/packages/commons/src/lib/markdown_renderer.ts@@ -387,6 +387,15 @@ export class CustomMarkdownRenderer extends Renderer {return super.image(token).replace(` alt=""`, "");}+ override table(token: Tokens.Table): string {+ // CKEditor wraps every table in `<figure class="table">`, and its content CSS+ // (`.ck-content .table`) styles that wrapper rather than a bare `<table>`. Without+ // it, imported tables render unstyled in read-only mode until the note is opened in+ // the editor — which re-wraps them on save (#10270). Emit the wrapper here so+ // imported markdown matches CKEditor's structure up front.+ return `<figure class="table">${super.table(token).trimEnd()}</figure>`;+ }+override blockquote({ tokens }: Tokens.Blockquote): string {const body = this.parser.parse(tokens);