Skip to content

Build your personal knowledge base with Trilium Notes

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

Elian Doran721bf455e12a
diff --git a/src/services/import/markdown.ts b/src/services/import/markdown.ts
index 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;
}