fix: normalize Windows paths to forward slashes for Typst

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 <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-11-09 22:20:23 +01:00
1 parent b322e6801c
commit cf4de4ce36
1 file changed
+30 -26
+30 -26
View File
@@ -285,35 +285,39 @@ export class PandocCommandBuilder {
* @private
*/
private async addTemplateConfiguration(args: string[], pandocOptions: PandocOptions): Promise<void> {
// 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.