feat(import/markdown): import in-line math properly

This commit is contained in:
Elian Doran 2025-04-05 09:59:10 +03:00
parent 07b5cd3b05
commit e6b9ecda5c
No known key found for this signature in database
2 changed files with 5 additions and 1 deletions

View File

@ -165,7 +165,7 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
it("converts inline math expressions into Mathtex format", () => { it("converts inline math expressions into Mathtex format", () => {
const input = `The equation is\u00a0$e=mc^{2}$.`; 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>`; const expected = /*html*/`<p>The equation is&nbsp;<span class="math-tex">\\(e=mc^{2}\\)</span>.</p>`;
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
}); });

View File

@ -18,6 +18,10 @@ class CustomMarkdownRenderer extends Renderer {
text = text.replaceAll(/\$\$(.+)\$\$/g, text = text.replaceAll(/\$\$(.+)\$\$/g,
`<span class="math-tex">\\\[$1\\\]</span>`); `<span class="math-tex">\\\[$1\\\]</span>`);
// Inline math
text = text.replaceAll(/\$(.+)\$/g,
`<span class="math-tex">\\\($1\\\)</span>`);
return text; return text;
} }