mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 18:42:28 +08:00
feat(import/markdown): import in-display math properly
This commit is contained in:
parent
fc4eb13e8d
commit
07b5cd3b05
@ -163,4 +163,16 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it("converts inline math expressions into Mathtex format", () => {
|
||||
const input = `The equation is\u00a0$e=mc^{2}$.`;
|
||||
const expected = /*html*/`<p>The equation is <span class="math-tex">\(e=mc^{2}\)</span>.</p>`;
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it("converts display math expressions into Mathtex format", () => {
|
||||
const input = `$$\sqrt{x^{2}+1}$$`;
|
||||
const expected = /*html*/`<p><span class="math-tex">\\[\sqrt{x^{2}+1}\\]</span></p>`;
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -12,7 +12,13 @@ class CustomMarkdownRenderer extends Renderer {
|
||||
}
|
||||
|
||||
paragraph(data: Tokens.Paragraph): string {
|
||||
return super.paragraph(data).trimEnd();
|
||||
let text = super.paragraph(data).trimEnd();
|
||||
|
||||
// Display math
|
||||
text = text.replaceAll(/\$\$(.+)\$\$/g,
|
||||
`<span class="math-tex">\\\[$1\\\]</span>`);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
code({ text, lang }: Tokens.Code): string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user