From 42ad862ba091d78349de9bab4a7130072a857d84 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 3 Sep 2025 19:21:13 +0200 Subject: [PATCH] Prioritizes config format in template variables Ensures that the format specified in the export configuration takes precedence over the default format specified in the settings when populating template variables for PDF conversion. Additionally, only uses the settings default for the export format if one is not already provided. --- main.ts | 8 +++++++- src/converters/PandocTypstConverter.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main.ts b/main.ts index 467e011..f2f4d8c 100644 --- a/main.ts +++ b/main.ts @@ -573,12 +573,18 @@ export class obsidianTypstPDFExport extends Plugin { this.templateManager.getTemplatePath('default.typ'); // Convert to PDF using the preprocessed content + const templateVariables = { + ...(config.templateVariables || {}), + // Add format from config if specified (takes priority over settings default) + ...(config.format && { export_format: config.format }) + }; + const result = await this.converter.convertMarkdownToPDF( processedResult.content, // Use preprocessed content instead of raw content outputPath, { template: templatePath, - variables: config.templateVariables || {}, + variables: templateVariables, pluginDir: pluginDir, vaultBasePath: vaultPath }, diff --git a/src/converters/PandocTypstConverter.ts b/src/converters/PandocTypstConverter.ts index 437c811..2e3644e 100644 --- a/src/converters/PandocTypstConverter.ts +++ b/src/converters/PandocTypstConverter.ts @@ -466,7 +466,7 @@ export class PandocTypstConverter { } } - // Add export format variable + // Add export format variable - only use settings default if not already provided if (!existingVars.export_format && settings.exportDefaults && settings.exportDefaults.format) { args.push('-V', `export_format=${settings.exportDefaults.format}`); }