From cf4de4ce364902e26beb39313db5934889a6e155 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Sun, 9 Nov 2025 22:20:23 +0100 Subject: [PATCH] fix: normalize Windows paths to forward slashes for Typst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Windows "syntax error" (OS error 123) when template paths contain backslashes. Typst interprets backslashes as escape characters, causing invalid filename syntax errors. Now converts all template paths to use forward slashes before passing to Typst via variables. Typst accepts forward slashes on all platforms including Windows. Fixes: #10 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/converters/pandoc/PandocCommandBuilder.ts | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/converters/pandoc/PandocCommandBuilder.ts b/src/converters/pandoc/PandocCommandBuilder.ts index f86844a..7565784 100644 --- a/src/converters/pandoc/PandocCommandBuilder.ts +++ b/src/converters/pandoc/PandocCommandBuilder.ts @@ -285,35 +285,39 @@ export class PandocCommandBuilder { * @private */ private async addTemplateConfiguration(args: string[], pandocOptions: PandocOptions): Promise { - // Use universal wrapper with --template and pass actual template as template_path variable - if (pandocOptions.template) { - const pathUtils = new PathUtils(this.plugin.app); - const absolutePluginDir = pandocOptions.pluginDir || ''; - const wrapperPath = pathUtils.joinPath(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); + // Use universal wrapper with --template and pass actual template as template_path variable + if (pandocOptions.template) { + const pathUtils = new PathUtils(this.plugin.app); + const absolutePluginDir = pandocOptions.pluginDir || ''; + const wrapperPath = pathUtils.joinPath(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); - // Verify wrapper exists - if (!(await pathUtils.fileExists(wrapperPath))) { - throw new Error(`Universal wrapper template not found at: ${wrapperPath}`); - } - - args.push('--template', wrapperPath); - - // Add plugin templates directory as a resource path so Typst can find template files - const templatesDir = pathUtils.joinPath(absolutePluginDir, 'templates'); - // Path quoting handled automatically by spawn - args.push('--resource-path', templatesDir); - - // Pass the actual template path as a variable - // Use relative path from vault root for Typst import - let templatePathForTypst = pandocOptions.template; - if (path.isAbsolute(templatePathForTypst) && pandocOptions.vaultBasePath) { - // Make template path relative to vault for Typst import - templatePathForTypst = path.relative(pandocOptions.vaultBasePath, templatePathForTypst); - } - - args.push('-V', `template_path=${templatePathForTypst}`); + // Verify wrapper exists + if (!(await pathUtils.fileExists(wrapperPath))) { + throw new Error(`Universal wrapper template not found at: ${wrapperPath}`); } + + args.push('--template', wrapperPath); + + // Add plugin templates directory as a resource path so Typst can find template files + const templatesDir = pathUtils.joinPath(absolutePluginDir, 'templates'); + // Path quoting handled automatically by spawn + args.push('--resource-path', templatesDir); + + // Pass the actual template path as a variable + // Use relative path from vault root for Typst import + let templatePathForTypst = pandocOptions.template; + if (path.isAbsolute(templatePathForTypst) && pandocOptions.vaultBasePath) { + // Make template path relative to vault for Typst import + templatePathForTypst = path.relative(pandocOptions.vaultBasePath, templatePathForTypst); + } + + // Normalize to forward slashes for Typst (Typst uses forward slashes on all platforms) + // This prevents Windows backslashes from being interpreted as escape characters in Typst + templatePathForTypst = templatePathForTypst.replace(/\\/g, '/'); + + args.push('-V', `template_path=${templatePathForTypst}`); } +} /** * Adds all Typst template variables mapped from export configuration.