diff --git a/main.ts b/main.ts index 90be292..b9ab7ec 100644 --- a/main.ts +++ b/main.ts @@ -448,8 +448,8 @@ export class obsidianTypstPDFExport extends Plugin { * Export a file with specific configuration */ private async exportFileWithConfig(file: TFile, config: ExportConfig): Promise { - const pluginDir = this.manifest.dir!; const vaultPath = (this.app.vault.adapter as any).basePath; + const pluginDir = path.join(vaultPath, this.manifest.dir!); // Create controller for this export (allows cancellation) this.currentExportController = new AbortController(); diff --git a/src/converters/PandocTypstConverter.ts b/src/converters/PandocTypstConverter.ts index 8d686ff..2e67dec 100644 --- a/src/converters/PandocTypstConverter.ts +++ b/src/converters/PandocTypstConverter.ts @@ -380,17 +380,22 @@ export class PandocTypstConverter { 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 = path.resolve(absolutePluginDir, 'templates'); + // Quote the path to handle spaces and special characters + args.push('--resource-path', `"${templatesDir}"`); + // Pass the actual template path as a variable - // Make the path relative to the vault (working directory) for Typst + // Use relative path from vault root for Typst import let templatePathForTypst = this.pandocOptions.template; - if (this.pandocOptions.vaultBasePath && path.isAbsolute(templatePathForTypst)) { - // If template path is absolute and inside vault, make it relative - if (templatePathForTypst.startsWith(this.pandocOptions.vaultBasePath)) { - templatePathForTypst = path.relative(this.pandocOptions.vaultBasePath, templatePathForTypst); - } + if (path.isAbsolute(templatePathForTypst) && this.pandocOptions.vaultBasePath) { + // Make template path relative to vault for Typst import + templatePathForTypst = path.relative(this.pandocOptions.vaultBasePath, templatePathForTypst); } + args.push('-V', `template_path=${templatePathForTypst}`); }