Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 308700d

Browse files
authored
Merge pull request #1906 from TriliumNext/importMarkdownfromClipboard
Fix incorrect import of multiple inline math.
2 parents 5f27357 + dea8fa4 commit 308700d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

apps/server/src/services/import/markdown.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
188188
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
189189
});
190190

191+
it("converts multiple inline math expressions into Mathtex format", () => {
192+
const input = `Energy: $e=mc^{2}$, Force: $F=ma$.`;
193+
const expected = /*html*/`<p>Energy: <span class="math-tex">\\(e=mc^{2}\\)</span>, Force: <span class="math-tex">\\(F=ma\\)</span>.</p>`;
194+
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
195+
});
196+
191197
it("converts display math expressions into Mathtex format", () => {
192198
const input = `$$\sqrt{x^{2}+1}$$`;
193199
const expected = /*html*/`<p><span class="math-tex">\\[\sqrt{x^{2}+1}\\]</span></p>`;

apps/server/src/services/import/markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CustomMarkdownRenderer extends Renderer {
2525
`<span class="math-tex">\\\[$1\\\]</span>`);
2626

2727
// Inline math
28-
text = text.replaceAll(/(?<!\\)\$(.+)\$/g,
28+
text = text.replaceAll(/(?<!\\)\$(.+?)\$/g,
2929
`<span class="math-tex">\\\($1\\\)</span>`);
3030
}
3131

0 commit comments

Comments
 (0)