Merge pull request #1906 from TriliumNext/importMarkdownfromClipboard

Fix incorrect import of multiple inline math.
This commit is contained in:
Elian Doran 2025-05-12 10:00:46 +03:00 committed by GitHub
commit 308700defd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -188,6 +188,12 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
}); });
it("converts multiple inline math expressions into Mathtex format", () => {
const input = `Energy: $e=mc^{2}$, Force: $F=ma$.`;
const expected = /*html*/`<p>Energy: <span class="math-tex">\\(e=mc^{2}\\)</span>, Force: <span class="math-tex">\\(F=ma\\)</span>.</p>`;
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
});
it("converts display math expressions into Mathtex format", () => { it("converts display math expressions into Mathtex format", () => {
const input = `$$\sqrt{x^{2}+1}$$`; const input = `$$\sqrt{x^{2}+1}$$`;
const expected = /*html*/`<p><span class="math-tex">\\[\sqrt{x^{2}+1}\\]</span></p>`; const expected = /*html*/`<p><span class="math-tex">\\[\sqrt{x^{2}+1}\\]</span></p>`;

View File

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