feat(import/markdown): preserve fractional widths

This commit is contained in:
Elian Doran 2025-04-05 20:36:20 +03:00
parent 8977926c00
commit 447439efd6
No known key found for this signature in database
4 changed files with 11 additions and 7 deletions

View File

@ -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);
});

View File

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

View File

@ -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, {

View File

@ -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", () => {