feat(import/markdown): preserve image width

This commit is contained in:
Elian Doran 2025-04-05 20:59:53 +03:00
parent 447439efd6
commit b6c185fd32
No known key found for this signature in database
3 changed files with 9 additions and 5 deletions

View File

@ -255,9 +255,10 @@ describe("Markdown export", () => {
it("preserves image verbatim if it has a width or height attribute", () => {
const scenarios = [
`<img src="Include Note_image.png" width="16" height="16">`,
`<img src="Include Note_image.png" width="16">`,
`<img src="Include Note_image.png" height="16">`
/*html*/`<img src="Include Note_image.png" width="16" height="16">`,
/*html*/`<img src="Include Note_image.png" width="16">`,
/*html*/`<img src="Include Note_image.png" height="16">`,
/*html*/`<img class="image_resized" style="aspect-ratio:853/315;width:50%;" src="6_File_image.png" width="853" height="315">`
];
for (const expected of scenarios) {
const html = /*html*/`<p>${expected}</p>`;

View File

@ -164,6 +164,8 @@ function sanitize(dirtyHtml: string) {
},
img: {
"aspect-ratio": [ /^\d+\/\d+$/ ],
width: sizeRegex,
height: sizeRegex
},
table: {
"border-color": colorRegex,

View File

@ -163,10 +163,11 @@ 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", () => {
it("preserves figures and images with sizes", () => {
const scenarios = [
/*html*/`<figure class="image image-style-align-center image_resized" style="width:53.44%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`,
/*html*/`<figure class="image image-style-align-center image_resized" style="width:53.44%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`
/*html*/`<figure class="image image-style-align-center image_resized" style="width:53.44%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`,
/*html*/`<img class="image_resized" style="aspect-ratio:853/315;width:50%;" src="6_File_image.png" width="853" height="315">`
];
for (const scenario of scenarios) {