@dragon708/docmind-markdown 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -825,6 +825,21 @@ function renderMarkdownSections(result, options) {
|
|
|
825
825
|
}));
|
|
826
826
|
}
|
|
827
827
|
|
|
828
|
+
// src/dynamic-import-runtime.ts
|
|
829
|
+
function isNodeJsRuntime() {
|
|
830
|
+
return typeof process !== "undefined" && process.versions != null && typeof process.versions.node === "string";
|
|
831
|
+
}
|
|
832
|
+
function importEsm(moduleId) {
|
|
833
|
+
if (isNodeJsRuntime()) {
|
|
834
|
+
return import(moduleId);
|
|
835
|
+
}
|
|
836
|
+
const run = new Function(
|
|
837
|
+
"id",
|
|
838
|
+
"return import(id)"
|
|
839
|
+
);
|
|
840
|
+
return run(moduleId);
|
|
841
|
+
}
|
|
842
|
+
|
|
828
843
|
// src/node-runtime.ts
|
|
829
844
|
function isNodeRuntime() {
|
|
830
845
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
@@ -843,7 +858,7 @@ function normalizeMammothMessages(messages) {
|
|
|
843
858
|
return messages.map((m) => ({ type: m.type, message: m.message }));
|
|
844
859
|
}
|
|
845
860
|
async function toNodeBuffer(input) {
|
|
846
|
-
const { Buffer: Buffer2 } = await
|
|
861
|
+
const { Buffer: Buffer2 } = await importEsm("node:buffer");
|
|
847
862
|
if (Buffer2.isBuffer(input)) return input;
|
|
848
863
|
if (input instanceof ArrayBuffer) return Buffer2.from(input);
|
|
849
864
|
return Buffer2.from(input);
|
|
@@ -896,9 +911,9 @@ async function convertDocxToMarkdown(input, options) {
|
|
|
896
911
|
const resolveStructured = options?.resolveStructured;
|
|
897
912
|
const structuredMdOpts = options?.structuredMarkdown;
|
|
898
913
|
const [{ default: mammoth }, { default: TurndownService }, { gfm }, buffer] = await Promise.all([
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
includeTables ?
|
|
914
|
+
importEsm("mammoth"),
|
|
915
|
+
importEsm("turndown"),
|
|
916
|
+
includeTables ? importEsm("turndown-plugin-gfm") : Promise.resolve({ gfm: null }),
|
|
902
917
|
toNodeBuffer(input)
|
|
903
918
|
]);
|
|
904
919
|
const styleMap = mergeStyleMaps(includePageBreaks, options?.mammoth?.styleMap);
|
|
@@ -995,7 +1010,7 @@ function engineOptions(options) {
|
|
|
995
1010
|
return rest;
|
|
996
1011
|
}
|
|
997
1012
|
async function toNodeBuffer2(input) {
|
|
998
|
-
const { Buffer: Buffer2 } = await
|
|
1013
|
+
const { Buffer: Buffer2 } = await importEsm("node:buffer");
|
|
999
1014
|
if (Buffer2.isBuffer(input)) return input;
|
|
1000
1015
|
if (input instanceof ArrayBuffer) return Buffer2.from(input);
|
|
1001
1016
|
return Buffer2.from(input);
|
|
@@ -1021,9 +1036,9 @@ async function convertPdfToMarkdown(input, options) {
|
|
|
1021
1036
|
inputPath = input;
|
|
1022
1037
|
} else {
|
|
1023
1038
|
const [{ mkdtemp, writeFile, rm }, { join }, { tmpdir }, buffer] = await Promise.all([
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1039
|
+
importEsm("node:fs/promises"),
|
|
1040
|
+
importEsm("node:path"),
|
|
1041
|
+
importEsm("node:os"),
|
|
1027
1042
|
toNodeBuffer2(input)
|
|
1028
1043
|
]);
|
|
1029
1044
|
const dir = await mkdtemp(join(tmpdir(), "docmind-markdown-pdf-"));
|
|
@@ -1033,7 +1048,9 @@ async function convertPdfToMarkdown(input, options) {
|
|
|
1033
1048
|
}
|
|
1034
1049
|
let convert;
|
|
1035
1050
|
try {
|
|
1036
|
-
({ convert } = await
|
|
1051
|
+
({ convert } = await importEsm(
|
|
1052
|
+
"@opendataloader/pdf"
|
|
1053
|
+
));
|
|
1037
1054
|
} catch (e) {
|
|
1038
1055
|
const hint = e instanceof Error && /Cannot find module|MODULE_NOT_FOUND/i.test(e.message) ? " Install `@opendataloader/pdf` in your project." : "";
|
|
1039
1056
|
warnings.push(
|
|
@@ -1267,8 +1284,10 @@ async function extractMarkdown(input, options) {
|
|
|
1267
1284
|
}
|
|
1268
1285
|
return { markdown: "", warnings, strategy: "path-requires-node" };
|
|
1269
1286
|
}
|
|
1270
|
-
const { readFile } = await
|
|
1271
|
-
|
|
1287
|
+
const { readFile } = await importEsm(
|
|
1288
|
+
"node:fs/promises"
|
|
1289
|
+
);
|
|
1290
|
+
const { basename } = await importEsm("node:path");
|
|
1272
1291
|
data = await readFile(input.path);
|
|
1273
1292
|
filename = input.filename ?? basename(input.path);
|
|
1274
1293
|
mimeType = input.mimeType;
|