mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-15 02:31:36 +08:00
fix(import/markdown): preserve escaped math expressions
This commit is contained in:
parent
721bf455e1
commit
4bb767f8ee
@ -175,4 +175,14 @@ 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("preserves escaped math expressions", () => {
|
||||
const scenarios = [
|
||||
"\\$\\$\sqrt{x^{2}+1}\\$\\$",
|
||||
"The equation is \\$e=mc^{2}\\$."
|
||||
];
|
||||
for (const scenario of scenarios) {
|
||||
expect(markdownService.renderToHtml(scenario, "Title")).toStrictEqual(`<p>${scenario}</p>`);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -16,11 +16,11 @@ class CustomMarkdownRenderer extends Renderer {
|
||||
|
||||
if (text.includes("$")) {
|
||||
// Display math
|
||||
text = text.replaceAll(/\$\$(.+)\$\$/g,
|
||||
text = text.replaceAll(/(?<!\\)\$\$(.+)\$\$/g,
|
||||
`<span class="math-tex">\\\[$1\\\]</span>`);
|
||||
|
||||
// Inline math
|
||||
text = text.replaceAll(/\$(.+)\$/g,
|
||||
text = text.replaceAll(/(?<!\\)\$(.+)\$/g,
|
||||
`<span class="math-tex">\\\($1\\\)</span>`);
|
||||
}
|
||||
|
||||
@ -87,6 +87,9 @@ import { ADMONITION_TYPE_MAPPINGS } from "../export/markdown.js";
|
||||
import utils from "../utils.js";
|
||||
|
||||
function renderToHtml(content: string, title: string) {
|
||||
// Double-escape slashes in math expression because they are otherwise consumed by the parser somewhere.
|
||||
content = content.replaceAll("\\$", "\\\\$");
|
||||
|
||||
let html = parse(content, {
|
||||
async: false,
|
||||
renderer: renderer
|
||||
|
Loading…
x
Reference in New Issue
Block a user