feat(export/markdown): export display math properly

This commit is contained in:
Elian Doran 2025-04-05 09:32:08 +03:00
parent 894cfe4f7a
commit fc4eb13e8d
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View File

@ -279,10 +279,16 @@ describe("Markdown export", () => {
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
it("converts inline math expressions to proper Markdown syntax", () => {
it("converts inline math expressions into proper Markdown syntax", () => {
const html = /*html*/`<p>The equation is&nbsp;<span class="math-tex">\(e=mc^{2}\)</span>.</p>`;
const expected = `The equation is\u00a0$e=mc^{2}$.`;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
it("converts display math expressions into proper Markdown syntax", () => {
const html = /*html*/`<span class="math-tex">\[\sqrt{x^{2}+1}\]</span>`;
const expected = `$$\sqrt{x^{2}+1}$$`;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
});

View File

@ -219,6 +219,11 @@ function buildMathFilter(): Rule {
return `$${content.substring(1, content.length - 1)}$`;
}
// Display math
if (content.startsWith("\\[") && content.endsWith("\\]")) {
return `$$${content.substring(2, content.length - 2)}$$`;
}
// Unknown.
return content;
}