Skip to content

Build your personal knowledge base with Trilium Notes

fix(markdown): colspan/rowspan not preserved

Elian Doranbde811dd0b63
diff --git a/packages/trilium-core/src/services/import/markdown.spec.ts b/packages/trilium-core/src/services/import/markdown.spec.ts
index a867a9139d..b88ad832eb 100644
--- a/packages/trilium-core/src/services/import/markdown.spec.ts
+++ b/packages/trilium-core/src/services/import/markdown.spec.ts
@@ -252,6 +252,21 @@ $$`;
expect(markdownService.renderToHtml(html, "Title")).toStrictEqual(html);
});
+ it("preserves table cell colspan", () => {
+ const html = /*html*/`<figure class="table"><table><tbody><tr><td colspan="2">Merged</td></tr><tr><td>A</td><td>B</td></tr></tbody></table></figure>`;
+ expect(markdownService.renderToHtml(html, "Title")).toStrictEqual(html);
+ });
+
+ it("preserves table cell rowspan", () => {
+ const html = /*html*/`<figure class="table"><table><tbody><tr><td rowspan="2">Merged</td><td>A</td></tr><tr><td>B</td></tr></tbody></table></figure>`;
+ expect(markdownService.renderToHtml(html, "Title")).toStrictEqual(html);
+ });
+
+ it("preserves colspan and rowspan together on header and body cells", () => {
+ const html = /*html*/`<figure class="table"><table><thead><tr><th colspan="2">Header</th></tr></thead><tbody><tr><td rowspan="2">Side</td><td>A</td></tr><tr><td>B</td></tr></tbody></table></figure>`;
+ expect(markdownService.renderToHtml(html, "Title")).toStrictEqual(html);
+ });
+
it("generates strike-through text", () => {
const input = `~~Hello~~ world.`;
const expected = /*html*/`<p><del>Hello</del> world.</p>`;
diff --git a/packages/trilium-core/src/services/sanitizer.ts b/packages/trilium-core/src/services/sanitizer.ts
index e1f190735b..632e2c5769 100644
--- a/packages/trilium-core/src/services/sanitizer.ts
+++ b/packages/trilium-core/src/services/sanitizer.ts
@@ -48,6 +48,8 @@ export function sanitizeHtml(dirtyHtml: string) {
li: ["id"],
input: ["type", "checked"],
img: ["width", "height"],
+ td: ["colspan", "rowspan"],
+ th: ["colspan", "rowspan"],
code: [ "spellcheck" ]
},
allowedStyles: {