feat: markitdown implementation
This commit is contained in:
parent
9ac5e7569b
commit
62c2be2592
2 changed files with 44 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import { convert as convertresvg, properties as propertiesresvg } from "./resvg"
|
||||||
import { convert as convertImage, properties as propertiesImage } from "./vips";
|
import { convert as convertImage, properties as propertiesImage } from "./vips";
|
||||||
import { convert as convertVtracer, properties as propertiesVtracer } from "./vtracer";
|
import { convert as convertVtracer, properties as propertiesVtracer } from "./vtracer";
|
||||||
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
|
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
|
||||||
|
import { convert as convertMarkitdown, properties as propertiesMarkitdown } from "./markitdown";
|
||||||
|
|
||||||
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
|
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
|
||||||
|
|
||||||
|
|
@ -127,6 +128,10 @@ const properties: Record<
|
||||||
properties: propertiesVtracer,
|
properties: propertiesVtracer,
|
||||||
converter: convertVtracer,
|
converter: convertVtracer,
|
||||||
},
|
},
|
||||||
|
MarkitDown: {
|
||||||
|
properties: propertiesMarkitdown,
|
||||||
|
converter: convertMarkitdown,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function chunks<T>(arr: T[], size: number): T[][] {
|
function chunks<T>(arr: T[], size: number): T[][] {
|
||||||
|
|
|
||||||
39
src/converters/markitdown.ts
Normal file
39
src/converters/markitdown.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { execFile as execFileOriginal } from "node:child_process";
|
||||||
|
import { ExecFileFn } from "./types";
|
||||||
|
|
||||||
|
export const properties = {
|
||||||
|
from: {
|
||||||
|
document: ["pdf", "powerpoint", "excel", "docx", "pptx", "html"],
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
document: ["md"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function convert(
|
||||||
|
filePath: string,
|
||||||
|
fileType: string,
|
||||||
|
convertTo: string,
|
||||||
|
targetPath: string,
|
||||||
|
options?: unknown,
|
||||||
|
execFile: ExecFileFn = execFileOriginal,
|
||||||
|
): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile("markitdown", [filePath, "-o", targetPath], (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
reject(`markitdown error: ${err}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout) {
|
||||||
|
console.log(`stdout: ${stdout}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`stderr: ${stderr}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve("Done");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue