diff --git a/main.ts b/main.ts index 6e29a60..579dd3f 100644 --- a/main.ts +++ b/main.ts @@ -127,44 +127,38 @@ export default class MarkitdownPlugin extends Plugin { async convertFile(filePath: string, outputPath: string): Promise { 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); }); }); } diff --git a/manifest.json b/manifest.json index 626edcd..4ef0da2 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/package.json b/package.json index 66f7392..73d0be5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/versions.json b/versions.json index 26382a1..189c17e 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,4 @@ { - "1.0.0": "0.15.0" + "1.0.0": "0.15.0", + "1.0.1": "0.15.0" }