mirror of
https://github.com/ethanolivertroy/obsidian-markitdown.git
synced 2026-07-22 05:41:54 +00:00
Fix Markitdown command execution syntax
- Update the command execution to better handle file paths with spaces - Add fallback to pipe-based execution if the direct command fails - Properly quote paths in command strings - Fix potential command-line syntax issues - Bump version to 1.0.1
This commit is contained in:
parent
199d5f2171
commit
eddb2bd30c
4 changed files with 26 additions and 31 deletions
50
main.ts
50
main.ts
|
|
@ -127,44 +127,38 @@ export default class MarkitdownPlugin extends Plugin {
|
|||
|
||||
async convertFile(filePath: string, outputPath: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Prepare command arguments
|
||||
let args = ['-m', 'markitdown'];
|
||||
// Build a command that matches the expected Markitdown syntax
|
||||
let command = `${this.settings.pythonPath} -m markitdown`;
|
||||
|
||||
// Add options based on settings
|
||||
if (this.settings.enablePlugins) {
|
||||
args.push('--use-plugins');
|
||||
command += ' --use-plugins';
|
||||
}
|
||||
|
||||
if (this.settings.docintelEndpoint) {
|
||||
args.push('-d');
|
||||
args.push('-e');
|
||||
args.push(this.settings.docintelEndpoint);
|
||||
command += ` -d -e "${this.settings.docintelEndpoint}"`;
|
||||
}
|
||||
|
||||
// Add input file and output options
|
||||
args.push(filePath);
|
||||
args.push('-o');
|
||||
args.push(outputPath);
|
||||
// Add input file and output options using the correct syntax
|
||||
// Use proper quoting around file paths to handle spaces
|
||||
command += ` "${filePath}" -o "${outputPath}"`;
|
||||
|
||||
const process = spawn(this.settings.pythonPath, args);
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
process.stdout.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
process.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
process.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve(stdout);
|
||||
} else {
|
||||
reject(new Error(`Markitdown exited with code ${code}: ${stderr}`));
|
||||
// Execute as a shell command
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// Try alternative approach using pipes if the first method fails
|
||||
const pipeCommand = `cat "${filePath}" | ${this.settings.pythonPath} -m markitdown > "${outputPath}"`;
|
||||
|
||||
exec(pipeCommand, (pipeError, pipeStdout, pipeStderr) => {
|
||||
if (pipeError) {
|
||||
reject(new Error(`Markitdown failed to convert the file: ${pipeError.message}\n${pipeStderr}`));
|
||||
return;
|
||||
}
|
||||
resolve(pipeStdout);
|
||||
});
|
||||
return;
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-markitdown",
|
||||
"name": "Markitdown File Converter",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Convert various file formats to Markdown using Microsoft's Markitdown library",
|
||||
"author": "Ethan Troy",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-markitdown",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Convert various file formats to Markdown using Microsoft's Markitdown library",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"1.0.0": "0.15.0"
|
||||
"1.0.0": "0.15.0",
|
||||
"1.0.1": "0.15.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue