feat: add comprehensive image embed support with WebP conversion

- Implement image embed processing similar to PDF embed handling
- Add marker-based preprocessing for async image resource handling
- Support all three Obsidian image linking patterns:
  - Shortest path (filename only): ![[auf_der_couch.png]]
  - Note-relative paths: ![[2023-05-04.../image.jpeg]]
  - Vault-relative paths: ![[../attachments/image.webp]]
- Add automatic WebP to PNG conversion using ImageMagick
- Copy images to vault temp directory for Typst accessibility
- Handle multiple path resolution strategies with fallback options
- Add comprehensive error handling and logging for image processing

Resolves image export issues where only text was included in PDF exports.
Images are now properly resolved, copied, and converted as needed for
Typst compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-08-31 15:03:00 +02:00
1 parent e80ccca966
commit 532bc04455
2 files changed
+178 -32

No files matched your search

+33 -32
View File
@@ -36,6 +36,14 @@ export interface PreprocessingResult {
options?: string;
marker: string;
}>;
imageEmbeds?: Array<{
originalPath: string;
sanitizedPath: string;
fileName: string;
baseName: string;
sizeOrAlt?: string;
marker: string;
}>;
};
/** Processing errors and warnings */
errors: string[];
@@ -439,41 +447,34 @@ export class MarkdownPreprocessor {
* Process image embeds with size parameters
*/
private processImageEmbed(imagePath: string, sizeOrAlt: string | undefined, result: PreprocessingResult): string {
// 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 `![${sizeOrAlt}](${resolvedPath})`;
const sanitizedPath = this.sanitizeFilePath(imagePath);
// For now, we'll mark this for async processing and return a placeholder
// The actual copying will be handled in the main export process
const fileName = imagePath.substring(imagePath.lastIndexOf('/') + 1);
const baseName = fileName.replace(/\.[^/.]+$/, ""); // Remove extension
// Create a marker that the export process can detect and replace
const marker = `IMAGE_EMBED_MARKER:${imagePath}:${baseName}:${sizeOrAlt || ''}`;
// Add to processing queue for later copying
if (!result.metadata.imageEmbeds) {
result.metadata.imageEmbeds = [];
}
result.metadata.imageEmbeds.push({
originalPath: imagePath,
sanitizedPath: sanitizedPath,
fileName: fileName,
baseName: baseName,
sizeOrAlt: sizeOrAlt,
marker: marker
});
result.warnings.push(`Image embed queued for processing: ${imagePath}`);
return marker;
}
// Standard image reference - Pandoc will convert to #figure(image("path")) for Typst
return `![](${resolvedPath})`;
}
/**
* Process video embeds
*/