Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/markdown): preserve fractional widths

Elian Doran447439efd6a7
diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.ts
index 67dfef5e6f..9368e11a68 100644
--- a/src/services/export/markdown.spec.ts
+++ b/src/services/export/markdown.spec.ts
@@ -267,12 +267,12 @@ describe("Markdown export", () => {
it("preserves figures", () => {
const html = /*html*/trimIndentation`\
- <figure class="image">
+ <figure class="image" style="width:53.44%;">
<img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991"
height="403">
</figure>
`;
- const expected = `<figure class="image"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
+ const expected = `<figure class="image" style="width:53.44%;"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
diff --git a/src/services/export/markdown.ts b/src/services/export/markdown.ts
index 2fc4fe468b..2b066caa79 100644
--- a/src/services/export/markdown.ts
+++ b/src/services/export/markdown.ts
@@ -2,7 +2,6 @@
import TurndownService, { type Rule } from "turndown";
import { gfm } from "../../../packages/turndown-plugin-gfm/src/gfm.js";
-import type { DOMElement } from "react";
let instance: TurndownService | null = null;
diff --git a/src/services/html_sanitizer.ts b/src/services/html_sanitizer.ts
index b4b6dae326..a86c15bb30 100644
--- a/src/services/html_sanitizer.ts
+++ b/src/services/html_sanitizer.ts
@@ -142,7 +142,7 @@ function sanitize(dirtyHtml: string) {
}
const colorRegex = [/^#(0x)?[0-9a-f]+$/i, /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/, /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/];
- const sizeRegex = [/^\d+(?:px|em|%)$/];
+ const sizeRegex = [/^\d+\.?\d*(?:px|em|%)$/];
// to minimize document changes, compress H
return sanitizeHtml(dirtyHtml, {
diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts
index 9ca6b6496d..9288350cf0 100644
--- a/src/services/import/markdown.spec.ts
+++ b/src/services/import/markdown.spec.ts
@@ -164,9 +164,14 @@ 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 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);
+ 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>`
+ ];
+
+ for (const scenario of scenarios) {
+ expect(markdownService.renderToHtml(scenario, "Title")).toStrictEqual(scenario);
+ }
});
it("converts inline math expressions into Mathtex format", () => {