diff --git a/package.json b/package.json index 2503ee043..a7e69eea6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", "build:prepare-dist": "npm run build:webpack && rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", - "test": "cross-env TRILIUM_DATA_DIR=./integration-tests/db vitest", + "test": "cross-env TRILIUM_DATA_DIR=./integration-tests/db TRILIUM_INTEGRATION_TEST=memory vitest", "test:coverage": "cross-env TRILIUM_DATA_DIR=./integration-tests/db vitest --coverage", "test:playwright": "playwright test", diff --git a/src/services/import/mime.ts b/src/services/import/mime.ts index 339f3b468..b329f12ac 100644 --- a/src/services/import/mime.ts +++ b/src/services/import/mime.ts @@ -88,7 +88,7 @@ function getType(options: TaskData, mime: string) { const mimeLc = mime?.toLowerCase(); switch (true) { - case options.textImportedAsText && ["text/html", "text/markdown", "text/x-markdown"].includes(mimeLc): + case options.textImportedAsText && ["text/html", "text/markdown", "text/x-markdown", "text/mdx"].includes(mimeLc): return "text"; case options.codeImportedAsCode && CODE_MIME_TYPES.has(mimeLc): diff --git a/src/services/import/samples/mdx.zip b/src/services/import/samples/mdx.zip new file mode 100644 index 000000000..cb01c501f Binary files /dev/null and b/src/services/import/samples/mdx.zip differ diff --git a/src/services/import/zip.spec.ts b/src/services/import/zip.spec.ts new file mode 100644 index 000000000..cd1ea9f5c --- /dev/null +++ b/src/services/import/zip.spec.ts @@ -0,0 +1,45 @@ +import { describe, expect, it } from "vitest"; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; +import { dirname } from "path"; +import zip from "./zip.js"; +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"; +const scriptDir = dirname(fileURLToPath(import.meta.url)); + +describe("processNoteContent", () => { + it("treats single MDX as Markdown in ZIP as text note", async () => { + const mdxSample = fs.readFileSync(path.join(scriptDir, "samples", "mdx.zip")); + const taskContext = TaskContext.getInstance("import-mdx", "import", { + textImportedAsText: true + }); + + await new Promise((resolve, reject) => { + cls.init(async () => { + initializeTranslations(); + sql_init.initializeDb(); + await sql_init.dbReady; + + const rootNote = becca.getNote("root"); + if (!rootNote) { + expect(rootNote).toBeTruthy(); + return; + } + + const importedNote = await zip.importZip(taskContext, mdxSample, rootNote as BNote); + try { + expect(importedNote.mime).toBe("text/mdx"); + expect(importedNote.type).toBe("text"); + } catch (e) { + reject(e); + } + resolve(); + }); + }); + }); +}) diff --git a/src/services/import/zip.ts b/src/services/import/zip.ts index 61534fed3..504f28382 100644 --- a/src/services/import/zip.ts +++ b/src/services/import/zip.ts @@ -386,7 +386,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo } function processNoteContent(noteMeta: NoteMeta | undefined, type: string, mime: string, content: string | Buffer, noteTitle: string, filePath: string) { - if ((noteMeta?.format === "markdown" || (!noteMeta && taskContext.data?.textImportedAsText && ["text/markdown", "text/x-markdown"].includes(mime))) && typeof content === "string") { + if ((noteMeta?.format === "markdown" || (!noteMeta && taskContext.data?.textImportedAsText && ["text/markdown", "text/x-markdown", "text/mdx"].includes(mime))) && typeof content === "string") { content = markdownService.renderToHtml(content, noteTitle); }