refactor(import/markdown): add guard condition for processing math

This commit is contained in:
Elian Doran 2025-04-05 09:59:42 +03:00
parent e6b9ecda5c
commit 721bf455e1
No known key found for this signature in database

View File

@ -14,13 +14,15 @@ class CustomMarkdownRenderer extends Renderer {
paragraph(data: Tokens.Paragraph): string {
let text = super.paragraph(data).trimEnd();
// Display math
text = text.replaceAll(/\$\$(.+)\$\$/g,
`<span class="math-tex">\\\[$1\\\]</span>`);
if (text.includes("$")) {
// Display math
text = text.replaceAll(/\$\$(.+)\$\$/g,
`<span class="math-tex">\\\[$1\\\]</span>`);
// Inline math
text = text.replaceAll(/\$(.+)\$/g,
`<span class="math-tex">\\\($1\\\)</span>`);
// Inline math
text = text.replaceAll(/\$(.+)\$/g,
`<span class="math-tex">\\\($1\\\)</span>`);
}
return text;
}