Enhances template handling for Typst exports.

Improves template resolution for Typst exports by adding the plugin's templates directory as a resource path. This allows Typst to correctly locate and utilize template files within the plugin.

Updates the template path handling to use relative paths from the vault root, ensuring proper import behavior within Typst.
This commit is contained in:
AlexKucera committed 2025-09-05 10:41:31 +02:00
1 parent 96660bfbba
commit d40253e6c4
2 files changed
+12 -7

No files matched your search

+1 -1
View File
@@ -448,8 +448,8 @@ export class obsidianTypstPDFExport extends Plugin {
* Export a file with specific configuration
*/
private async exportFileWithConfig(file: TFile, config: ExportConfig): Promise<void> {
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();
+11 -6
View File
@@ -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}`);
}