fix: Add attachment support to PDF export
- Run Pandoc from vault directory for proper path resolution - Add --resource-path arguments for attachment directories - Use absolute template paths when working directory is vault - Preserve relative attachment paths in MarkdownPreprocessor - Support common attachment folder structures (attachments/, assets/, files/, images/) Fixes issue where exported PDFs only contained text without embedded images/attachments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2 files changed
+539
-275
No files matched your search
+33
-24
@@ -431,32 +431,41 @@ export class MarkdownPreprocessor {
|
||||
* Process image embeds with size parameters
|
||||
*/
|
||||
private processImageEmbed(imagePath: string, sizeOrAlt: string | undefined, result: PreprocessingResult): string {
|
||||
const sanitizedPath = this.sanitizeFilePath(imagePath);
|
||||
|
||||
// Parse size information if provided
|
||||
if (sizeOrAlt) {
|
||||
const sizeMatch = sizeOrAlt.match(this.EMBED_SIZE_PATTERN);
|
||||
if (sizeMatch) {
|
||||
const width = sizeMatch[1];
|
||||
const height = sizeMatch[2];
|
||||
|
||||
// Create image with size attributes (optimized for Pandoc → Typst conversion)
|
||||
// Pandoc will convert these to #figure(image("path", width: X, height: Y)) for Typst
|
||||
if (height) {
|
||||
return `<img src="${sanitizedPath}" width="${width}" height="${height}" alt="" />`;
|
||||
} else {
|
||||
return `<img src="${sanitizedPath}" width="${width}" alt="" />`;
|
||||
}
|
||||
} else {
|
||||
// Treat as alt text
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard image reference - Pandoc will convert to #figure(image("path")) for Typst
|
||||
return ``;
|
||||
// Don't sanitize the path - keep it as-is for Pandoc to resolve
|
||||
// Pandoc with --resource-path will handle the path resolution
|
||||
let resolvedPath = imagePath;
|
||||
|
||||
// If path doesn't start with / or contain :, it's likely a vault-relative path
|
||||
// Keep it as-is since Pandoc will resolve it using --resource-path
|
||||
if (!imagePath.startsWith('/') && !imagePath.includes(':')) {
|
||||
// This is a vault-relative path - keep it exactly as Obsidian stores it
|
||||
resolvedPath = imagePath;
|
||||
}
|
||||
|
||||
// Parse size information if provided
|
||||
if (sizeOrAlt) {
|
||||
const sizeMatch = sizeOrAlt.match(this.EMBED_SIZE_PATTERN);
|
||||
if (sizeMatch) {
|
||||
const width = sizeMatch[1];
|
||||
const height = sizeMatch[2];
|
||||
|
||||
// Create image with size attributes (optimized for Pandoc → Typst conversion)
|
||||
// Pandoc will convert these to #figure(image("path", width: X, height: Y)) for Typst
|
||||
if (height) {
|
||||
return `<img src="${resolvedPath}" width="${width}" height="${height}" alt="" />`;
|
||||
} else {
|
||||
return `<img src="${resolvedPath}" width="${width}" alt="" />`;
|
||||
}
|
||||
} else {
|
||||
// Treat as alt text
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard image reference - Pandoc will convert to #figure(image("path")) for Typst
|
||||
return ``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process video embeds
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user