mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-22 12:11:41 +08:00
feat(import/zip): treat mdx as markdown (closes #1236)
This commit is contained in:
parent
1c118f2aa9
commit
f9e4ae7210
@ -49,7 +49,7 @@
|
|||||||
"build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts",
|
"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",
|
"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:coverage": "cross-env TRILIUM_DATA_DIR=./integration-tests/db vitest --coverage",
|
||||||
"test:playwright": "playwright test",
|
"test:playwright": "playwright test",
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ function getType(options: TaskData, mime: string) {
|
|||||||
const mimeLc = mime?.toLowerCase();
|
const mimeLc = mime?.toLowerCase();
|
||||||
|
|
||||||
switch (true) {
|
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";
|
return "text";
|
||||||
|
|
||||||
case options.codeImportedAsCode && CODE_MIME_TYPES.has(mimeLc):
|
case options.codeImportedAsCode && CODE_MIME_TYPES.has(mimeLc):
|
||||||
|
BIN
src/services/import/samples/mdx.zip
Normal file
BIN
src/services/import/samples/mdx.zip
Normal file
Binary file not shown.
45
src/services/import/zip.spec.ts
Normal file
45
src/services/import/zip.spec.ts
Normal file
@ -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<void>((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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
@ -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) {
|
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);
|
content = markdownService.renderToHtml(content, noteTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user