Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(import/markdown): add guard condition for processing math
Elian Doran721bf455e12a
diff --git a/src/services/import/markdown.ts b/src/services/import/markdown.tsindex 6cc46caec9..60f770bbdf 100644--- a/src/services/import/markdown.ts+++ b/src/services/import/markdown.ts@@ -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>`);-- // Inline 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>`);+ }return text;}