mirror of
https://github.com/zadam/trilium.git
synced 2025-10-26 07:46:30 +01:00
feat(import/single): treat mdx as markdown
This commit is contained in:
21
src/services/import/samples/Text Note.mdx
Normal file
21
src/services/import/samples/Text Note.mdx
Normal file
@@ -0,0 +1,21 @@
|
||||
Page 1
|
||||
|
||||
Heading 1
|
||||
---------
|
||||
|
||||
Heading 2
|
||||
---------
|
||||
|
||||
### Heading 3
|
||||
|
||||
```
|
||||
class Foo {
|
||||
hoistedNoteChangedEvent({ ntxId }) {
|
||||
if (this.isNoteContext(ntxId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Page 2
|
||||
49
src/services/import/single.spec.ts
Normal file
49
src/services/import/single.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
import becca from "../../becca/becca.js";
|
||||
import BNote from "../../becca/entities/bnote.js";
|
||||
import TaskContext from "../task_context.js";
|
||||
import cls from "../cls.js";
|
||||
import sql_init from "../sql_init.js";
|
||||
import { initializeTranslations } from "../i18n.js";
|
||||
import single from "./single.js";
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
describe("processNoteContent", () => {
|
||||
it("treats single MDX as Markdown", async () => {
|
||||
const mdxSample = fs.readFileSync(path.join(scriptDir, "samples", "Text Note.mdx"));
|
||||
const taskContext = TaskContext.getInstance("import-mdx", "import", {
|
||||
textImportedAsText: true
|
||||
});
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
cls.init(async () => {
|
||||
initializeTranslations();
|
||||
sql_init.initializeDb();
|
||||
await sql_init.dbReady;
|
||||
|
||||
const rootNote = becca.getNote("root");
|
||||
if (!rootNote) {
|
||||
reject("Missing root note.");
|
||||
}
|
||||
|
||||
const importedNote = single.importSingleFile(taskContext, {
|
||||
originalname: "Text Note.mdx",
|
||||
mimetype: "text/mdx",
|
||||
buffer: mdxSample
|
||||
}, rootNote as BNote);
|
||||
try {
|
||||
expect(importedNote.mime).toBe("text/html");
|
||||
expect(importedNote.type).toBe("text");
|
||||
expect(importedNote.title).toBe("Text Note");
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
@@ -19,7 +19,7 @@ function importSingleFile(taskContext: TaskContext, file: File, parentNote: BNot
|
||||
if (taskContext?.data?.textImportedAsText) {
|
||||
if (mime === "text/html") {
|
||||
return importHtml(taskContext, file, parentNote);
|
||||
} else if (["text/markdown", "text/x-markdown"].includes(mime)) {
|
||||
} else if (["text/markdown", "text/x-markdown", "text/mdx"].includes(mime)) {
|
||||
return importMarkdown(taskContext, file, parentNote);
|
||||
} else if (mime === "text/plain") {
|
||||
return importPlainText(taskContext, file, parentNote);
|
||||
|
||||
Reference in New Issue
Block a user