feat(import/single): mermaid with .mmd extension

This commit is contained in:
Elian Doran 2025-03-22 15:45:36 +02:00
parent 3dae771e90
commit 858ad91708
No known key found for this signature in database
5 changed files with 22 additions and 2 deletions

View File

@ -30,6 +30,10 @@ describe("#getMime", () => {
"File extension ('.mermaid') that is defined in EXTENSION_TO_MIME", "File extension ('.mermaid') that is defined in EXTENSION_TO_MIME",
["test.mermaid"], "text/vnd.mermaid" ["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", "File extension with inconsistent capitalization that is defined in EXTENSION_TO_MIME",

View File

@ -70,7 +70,8 @@ const EXTENSION_TO_MIME = new Map<string, string>([
[".swift", "text/x-swift"], [".swift", "text/x-swift"],
[".ts", "text/x-typescript"], [".ts", "text/x-typescript"],
[".excalidraw", "application/json"], [".excalidraw", "application/json"],
[".mermaid", "text/vnd.mermaid"] [".mermaid", "text/vnd.mermaid"],
[".mmd", "text/vnd.mermaid"]
]); ]);
/** @returns false if MIME is not detected */ /** @returns false if MIME is not detected */

View File

@ -0,0 +1,5 @@
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;

View File

@ -97,7 +97,7 @@ describe("processNoteContent", () => {
expect(importedNote.title).toBe("New note"); 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"); const { importedNote } = await testImport("New note.mermaid", "application/json");
expect(importedNote).toMatchObject({ expect(importedNote).toMatchObject({
mime: "text/vnd.mermaid", mime: "text/vnd.mermaid",
@ -105,4 +105,13 @@ describe("processNoteContent", () => {
title: "New note" 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"
});
});
}); });

View File

@ -182,6 +182,7 @@ export function removeTextFileExtension(filePath: string) {
case ".htm": case ".htm":
case ".excalidraw": case ".excalidraw":
case ".mermaid": case ".mermaid":
case ".mmd":
return filePath.substring(0, filePath.length - extension.length); return filePath.substring(0, filePath.length - extension.length);
default: default:
return filePath; return filePath;