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
feat(export/markdown): export display math properly
Elian Doranfc4eb13e8d16
diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.tsindex 2726481af3..24aa77da20 100644--- a/src/services/export/markdown.spec.ts+++ b/src/services/export/markdown.spec.ts@@ -279,10 +279,16 @@ describe("Markdown export", () => {expect(markdownExportService.toMarkdown(html)).toBe(expected);});- it("converts inline math expressions to proper Markdown syntax", () => {+ it("converts inline math expressions into proper Markdown syntax", () => {const html = /*html*/`<p>The equation is <span class="math-tex">\(e=mc^{2}\)</span>.</p>`;const expected = `The equation is\u00a0$e=mc^{2}$.`;expect(markdownExportService.toMarkdown(html)).toBe(expected);});+ it("converts display math expressions into proper Markdown syntax", () => {+ const html = /*html*/`<span class="math-tex">\[\sqrt{x^{2}+1}\]</span>`;+ const expected = `$$\sqrt{x^{2}+1}$$`;+ expect(markdownExportService.toMarkdown(html)).toBe(expected);+ });+});diff --git a/src/services/export/markdown.ts b/src/services/export/markdown.tsindex cbc4809845..731024435c 100644--- a/src/services/export/markdown.ts+++ b/src/services/export/markdown.ts@@ -219,6 +219,11 @@ function buildMathFilter(): Rule {return `$${content.substring(1, content.length - 1)}$`;}+ // Display math+ if (content.startsWith("\\[") && content.endsWith("\\]")) {+ return `$$${content.substring(2, content.length - 2)}$$`;+ }+// Unknown.return content;}