Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/markdown): preserve figure image size

Elian Doran64ccea570283
diff --git a/src/services/html_sanitizer.ts b/src/services/html_sanitizer.ts
index c1e18bb413..b4b6dae326 100644
--- a/src/services/html_sanitizer.ts
+++ b/src/services/html_sanitizer.ts
@@ -149,7 +149,8 @@ function sanitize(dirtyHtml: string) {
allowedTags,
allowedAttributes: {
"*": ["class", "style", "title", "src", "href", "hash", "disabled", "align", "alt", "center", "data-*"],
- input: ["type", "checked"]
+ input: ["type", "checked"],
+ img: ["width", "height"]
},
allowedStyles: {
"*": {
@@ -161,6 +162,9 @@ function sanitize(dirtyHtml: string) {
width: sizeRegex,
height: sizeRegex
},
+ img: {
+ "aspect-ratio": [ /^\d+\/\d+$/ ],
+ },
table: {
"border-color": colorRegex,
"border-style": [/^\s*(none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset)\s*$/]
diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts
index e25a8bc099..cf75fc1afd 100644
--- a/src/services/import/markdown.spec.ts
+++ b/src/services/import/markdown.spec.ts
@@ -163,6 +163,12 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
});
+ 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>`;
+ expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
+ });
+
it("converts inline math expressions into Mathtex format", () => {
const input = `The equation is\u00a0$e=mc^{2}$.`;
const expected = /*html*/`<p>The equation is&nbsp;<span class="math-tex">\\(e=mc^{2}\\)</span>.</p>`;