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(import/single): mermaid with .mmd extension
Elian Doran858ad9170871
diff --git a/src/services/import/mime.spec.ts b/src/services/import/mime.spec.tsindex 7281d31c2a..5b04d0f2ac 100644--- a/src/services/import/mime.spec.ts+++ b/src/services/import/mime.spec.ts@@ -30,6 +30,10 @@ describe("#getMime", () => {"File extension ('.mermaid') that is defined in EXTENSION_TO_MIME",["test.mermaid"], "text/vnd.mermaid"],+ [+ "File extension ('.mermaid') that is defined in EXTENSION_TO_MIME",+ ["test.mmd"], "text/vnd.mermaid"+ ],["File extension with inconsistent capitalization that is defined in EXTENSION_TO_MIME",diff --git a/src/services/import/mime.ts b/src/services/import/mime.tsindex cb400b8d82..5f050184f8 100644--- a/src/services/import/mime.ts+++ b/src/services/import/mime.ts@@ -70,7 +70,8 @@ const EXTENSION_TO_MIME = new Map<string, string>([[".swift", "text/x-swift"],[".ts", "text/x-typescript"],[".excalidraw", "application/json"],- [".mermaid", "text/vnd.mermaid"]+ [".mermaid", "text/vnd.mermaid"],+ [".mmd", "text/vnd.mermaid"]]);/** @returns false if MIME is not detected */diff --git a/src/services/import/samples/New note.mmd b/src/services/import/samples/New note.mmdnew file mode 100644index 0000000000..577e633599--- /dev/null+++ b/src/services/import/samples/New note.mmd@@ -0,0 +1,5 @@+graph TD;+ A-->B;+ A-->C;+ B-->D;+ C-->D;\ No newline at end of filediff --git a/src/services/import/single.spec.ts b/src/services/import/single.spec.tsindex 060801eb99..e26934b08a 100644--- a/src/services/import/single.spec.ts+++ b/src/services/import/single.spec.ts@@ -97,7 +97,7 @@ describe("processNoteContent", () => {expect(importedNote.title).toBe("New note");});- it("supports mermaid note", async () => {+ it("imports .mermaid as mermaid note", async () => {const { importedNote } = await testImport("New note.mermaid", "application/json");expect(importedNote).toMatchObject({mime: "text/vnd.mermaid",@@ -105,4 +105,13 @@ describe("processNoteContent", () => {title: "New note"});});++ it("imports .mmd as mermaid note", async () => {+ const { importedNote } = await testImport("New note.mmd", "application/json");+ expect(importedNote).toMatchObject({+ mime: "text/vnd.mermaid",+ type: "mermaid",+ title: "New note"+ });+ });});diff --git a/src/services/utils.ts b/src/services/utils.tsindex 87dcf2d67f..926e24fb41 100644--- a/src/services/utils.ts+++ b/src/services/utils.ts@@ -182,6 +182,7 @@ export function removeTextFileExtension(filePath: string) {case ".htm":case ".excalidraw":case ".mermaid":+ case ".mmd":return filePath.substring(0, filePath.length - extension.length);default:return filePath;