feat(import/markdown): preserve figure image size

This commit is contained in:
Elian Doran 2025-04-05 11:37:26 +03:00
parent 7293f59a80
commit 64ccea5702
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View File

@ -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*$/]

View File

@ -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>`;