Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/markdown): preserve trailing semicolon in figure style

Elian Dorancdb5ebb08076
diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts
index 91389350c4..9ca6b6496d 100644
--- a/src/services/import/markdown.spec.ts
+++ b/src/services/import/markdown.spec.ts
@@ -164,8 +164,8 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
});
it("preserves figures", () => {
- const input = `<figure class="image"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
- const expected = /*html*/`<figure class="image"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
+ const input = `<figure class="image image-style-align-center image_resized" style="width:50%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
+ const expected = /*html*/`<figure class="image image-style-align-center image_resized" style="width:50%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
});
diff --git a/src/services/import/markdown.ts b/src/services/import/markdown.ts
index 22dd9cab9c..a4b5419792 100644
--- a/src/services/import/markdown.ts
+++ b/src/services/import/markdown.ts
@@ -100,7 +100,7 @@ function renderToHtml(content: string, title: string) {
html = htmlSanitizer.sanitize(html);
// Add a trailing semicolon to CSS styles.
- html = html.replaceAll(/(<img style=".*?)"/g, "$1;\"");
+ html = html.replaceAll(/(<(img|figure).*?style=".*?)"/g, "$1;\"");
// Remove slash for self-closing tags to match CKEditor's approach.
html = html.replace(/<(\w+)([^>]*)\s+\/>/g, "<$1$2>");