Commit Graph
37 Commits
Author SHA1 Message Date
Jarvis fa44c50dc6 refactor: extract PDF processing utilities to PdfProcessor.ts
Extract PDF validation and metadata operations from PdfToImageConverter
to improve modularity and separation of concerns.

Changes:
- Create src/converters/pdf/PdfProcessor.ts with PDF utilities
- Move isValidPdf() and getPdfInfo() methods with full implementations
- Add validatePdfFile() and isValidPdfFile() helper methods
- Update PdfToImageConverter.ts to delegate to PdfProcessor
- Maintain backward compatibility for all existing method signatures

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 12:56:12 +02:00
Jarvis 3b926fce12 refactor: complete PandocTypstConverter modularization
Extract process execution and PDF embed processing to dedicated modules:
- PandocExecutor: handles pandoc process spawning, monitoring, and error parsing
- PdfEmbedProcessor: manages PDF to image conversion and embed replacement

PandocTypstConverter reduced from 741 to 202 lines, now serves as clean
orchestrator delegating to specialized modules. Maintains identical functionality
while improving maintainability and testability.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 12:17:01 +02:00
Jarvis 1fc47fe9ae refactor: extract ResourcePathResolver from PandocCommandBuilder
Create dedicated ResourcePathResolver to handle resource path discovery and caching:

- Extract resource path caching logic (~110 lines)
- Move vault scanning and attachment directory discovery
- Eliminate code duplication: remove duplicate resolveExecutablePath()
- Simplify PandocCommandBuilder from ~287 to ~204 lines

Changes:
- NEW: src/converters/pandoc/ResourcePathResolver.ts
- MODIFIED: PandocCommandBuilder - use ResourcePathResolver and PathResolver
- MODIFIED: PandocTypstConverter - use centralized PathResolver

Benefits:
- Clear separation of concerns
- Reusable resource path logic
- Reduced code duplication
- Better maintainability

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 12:05:57 +02:00
Jarvis 84bd5fb674 refactor: extract TypstVariableMapper from PandocCommandBuilder
Extract comprehensive variable mapping and transformation logic into
dedicated TypstVariableMapper class. This modularizes the variable handling
system for better maintainability and separation of concerns.

Changes:
- Create src/converters/pandoc/TypstVariableMapper.ts (320+ lines)
- Extract addExportConfigVariables and addPluginSettingsVariables methods
- Extract complete variable transformation logic with name mapping
- Extract typography and page setup variable handling
- Update PandocCommandBuilder to use new variable mapper
- Remove 127 lines of variable mapping code from PandocCommandBuilder

Key Features:
- TypstVariable interface for structured variable handling
- Priority system: ExportConfig variables override plugin settings
- Complete variable name mapping (bodyFont → font, margins + 'cm', etc.)
- Modular variable mapping: ExportConfig, Typography, PageSetup, Margins
- Unit conversion handling (pt, cm) and paper size mapping
- Pandoc argument generation from mapped variables

Maintains all existing functionality:
- Variable priority and fallback system preserved
- All font, layout, and template variable mappings intact
- Plugin settings integration with proper precedence
- Paper size mapping via mapToTypstPaperSize utility

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 11:52:07 +02:00
Jarvis 3e49d4ade6 refactor: extract PandocCommandBuilder from PandocTypstConverter
Extract comprehensive Pandoc command-line argument construction logic
into dedicated PandocCommandBuilder class. This modularizes the 280-line
buildPandocArgs method and associated utilities for better maintainability.

Changes:
- Create src/converters/pandoc/PandocCommandBuilder.ts (400+ lines)
- Extract buildPandocArgs, resolveExecutablePath methods
- Extract resource path caching and scanning logic
- Extract template configuration, variable mapping, and engine options
- Update PandocTypstConverter to use new command builder
- Extend PandocOptions interface with tempDir, cleanupHandlers, typstSettings

Maintains all existing functionality including:
- 5-minute resource path caching optimization
- ExportConfig variable priority over plugin settings
- Template path resolution and validation
- Intermediate Typst file generation for debugging
- Executable path resolution with system search fallback

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 11:46:44 +02:00
Jarvis 57555fa859 refactor: finalize MarkdownPreprocessor as clean orchestrator
- Remove unused regex patterns (WIKILINK_PATTERN, TAG_PATTERN)
- Fix step numbering in processing pipeline (1-6 sequential)
- Remove extra whitespace and improve code organization
- Reduce from 213 to 204 lines (target ~200 lines achieved)
- Clean orchestration focused on delegation to processors
- Build verification passes without errors

MarkdownPreprocessor now serves as pure orchestrator:
- Configuration management and processor coordination
- 6-step processing pipeline with clear delegation
- No trapped implementation details in main class
- Clean error handling and result compilation

Phase 2 complete: 1792 → 204 lines (88% reduction)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 22:45:46 +02:00
Jarvis 09365e2d75 refactor: remove unused metadata extraction (tags/wordCount)
- Remove extractTags() and calculateWordCount() methods (dead code)
- Keep only extractTitle() method in MetadataExtractor
- Remove includeMetadata option and related infrastructure
- Update PreprocessingResult interfaces across all processors
- Remove wordCount from metadata schema
- Tags still populated from frontmatter (FrontmatterProcessor)
- Build verification passes without errors

Analysis showed these methods extracted data never consumed by Typst
templates or PDF generation pipeline.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 22:39:38 +02:00
Jarvis a6b35d336a refactor: extract MetadataExtractor from MarkdownPreprocessor
- Create MetadataExtractor.ts with static utility methods
- Extract extractTags(), calculateWordCount(), and extractTitle() methods
- Maintain complete implementation logic and regex patterns
- Update MarkdownPreprocessor to use MetadataExtractor
- Remove 65 lines from MarkdownPreprocessor (280→215 lines)
- Build verification passes without errors

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 22:31:12 +02:00
Jarvis 86a339197f refactor: extract CalloutProcessor from MarkdownPreprocessor
- Create CalloutProcessor.ts with comprehensive callout and email block processing
- Extract 10 methods with complete implementations (~350 lines):
  - processCallouts/processEmailBlocks (main entry points)
  - processMultiLineCallouts/extractCalloutBlock/convertCalloutToTypstFormat
  - processEmailBlock/parseEmailYaml (email block processing)
  - escapeQuotes/escapeBodyForTypst (string escaping utilities)
  - filterUnnecessaryLinks (link filtering)
- Update MarkdownPreprocessor.ts to delegate to CalloutProcessor
- Remove extracted methods and unused pattern constants
- Reduce MarkdownPreprocessor from 653 to 346 lines (307 line reduction)
- Maintain full backward compatibility through delegation pattern

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 22:22:17 +02:00
Jarvis 9960f63650 refactor: extract EmbedProcessor and fix WebP conversion
- Extract embed processing logic from MarkdownPreprocessor to new EmbedProcessor module
- Fix WebP image conversion that was broken during refactoring:
  - Update ImageMagick command from deprecated 'convert' to modern 'magick'
  - Fix field name mismatch: use 'sizeOrAlt' instead of 'alt' in plugin/EmbedProcessor
  - Use PathResolver for proper ImageMagick executable path resolution
- Restore comprehensive embed processing including images, PDFs, and files
- Add proper error handling and fallback for WebP conversion failures
- Maintain size parameter parsing (e.g., "400x300") vs alt text differentiation

Resolves WebP conversion issues and completes Step 2.3 of refactoring plan.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 15:58:24 +02:00
Jarvis 989d839de8 refactor: extract WikilinkProcessor from MarkdownPreprocessor
Extract comprehensive wikilink processing functionality into separate module:
- Move processWikilinks() method with complete implementation
- Extract sanitizeFilePath() as public method for reuse by embed processors
- Move sanitizeHeadingForLink() and resolveRelativePath() methods
- Remove duplicate WikilinkConfig interface
- Update all embed processors to use WikilinkProcessor.sanitizeFilePath()
- Add WikilinkProcessor configuration sync in updateConfig()
- Preserve all existing functionality and error handling

Reduces MarkdownPreprocessor from 895 to 816 lines (-79 lines).
WikilinkProcessor: 172 lines of focused wikilink processing logic.
Build passes successfully with no breaking changes.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 15:35:44 +02:00
Jarvis 3843788351 refactor: extract FrontmatterProcessor from MarkdownPreprocessor
Extract complete frontmatter processing functionality (260 lines) into a dedicated
FrontmatterProcessor module to improve code organization and maintainability.

Changes:
- Create src/converters/preprocessors/FrontmatterProcessor.ts with complete implementation
- Extract processFrontmatter() method including gray-matter and regex fallback parsing
- Extract formatFrontmatterForDisplay() method with all formatting logic
- Move FRONTMATTER_PATTERN regex and all frontmatter-related dependencies
- Update MarkdownPreprocessor.ts to delegate to FrontmatterProcessor
- Reduce MarkdownPreprocessor.ts from 1,166 to 906 lines (22% reduction)

All functionality preserved:
- Gray-matter primary parsing with js-yaml fallback
- Tag extraction and metadata population
- Title override and noteTitle handling
- preserveFrontmatter and printFrontmatter options
- Error handling and warning accumulation
- Fallback regex parsing for malformed YAML

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 14:41:22 +02:00
Jarvis 676d634d0b fix: simplify file type classification to fix DOCX embedding
- Reduce file type classification from 6+ types to 3: image, pdf, file
- Remove processVideoEmbed, processAudioEmbed, processDocumentEmbed methods
- Fix DOCX files not being embedded (were classified as 'document' → links only)
- All non-image/non-PDF files now properly embedded via processFileEmbed
- Update switch statement to handle only the 3 simplified file types
- Maintain backward compatibility for existing functionality

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 10:50:44 +02:00
Jarvis 8879f40be5 fix: update ImageMagick to use 'magick' instead of deprecated 'convert'
- Update default ImageMagick executable from 'convert' to 'magick' in constants
- Remove deprecated 'convert' subcommand from ImageMagick spawn calls
- Update UI labels and settings descriptions to reflect 'magick' command
- Fix pdf2img PATH environment to include Node.js installation paths

This resolves ImageMagick v7 deprecation warning and fixes pdf2img execution
failure caused by missing Node.js in PATH. The 'convert' command was deprecated
in ImageMagick v7 in favor of the unified 'magick' command.

Fixes: "env: node: No such file or directory" error in pdf2img execution

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 10:55:27 +02:00
Jarvis 1b36ebb705 fix(core): enhance dependency checker with comprehensive path resolution
- Add support for user-configured additionalPaths in dependency checking
- Implement comprehensive default system paths (home-relative and absolute)
- Update path resolution to handle both full paths and bare executable names
- Use 'which' command fallback with augmented PATH for executable discovery
- Ensure consistent path handling across sync and async dependency methods

This resolves issues where executables installed in common locations like
/opt/homebrew/bin were not found when executable path settings were empty.
The plugin now searches standard package manager installation directories
by default while respecting user-configured additional paths.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 10:32:16 +02:00
Jarvis a1380d88a0 fix: address Obsidian Review Bot feedback for plugin submission
- Replace hardcoded '.obsidian' paths with Vault#configDir for proper config directory support
- Move inline styles to CSS classes for better theme compatibility
- Remove unnecessary type casting by using proper type predicates
- Add proper TypeScript type narrowing for filtered arrays

This addresses all required issues identified by the Obsidian Review Bot:
* TempDirectoryManager now accepts configDir parameter from app.vault.configDir
* PdfToImageConverter uses configDir instead of hardcoded '.obsidian'
* ExportConfigModal uses CSS classes (.export-progress-visible, .export-form-hidden) instead of inline styles
* Progress bar width controlled via CSS custom property --progress-width
* Removed 'as TFile[]' casting by implementing isMarkdownFile type predicate

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 23:10:31 +02:00
AlexKucera 31cbb0010e Merge branch 'develop' into feature/generic_embed 2025-09-05 18:03:49 +02:00
AlexKucera 5519c98957 Improves plugin directory path handling dynamically
Updates file path resolution to use plugin manifest directory dynamically

Replaces hardcoded plugin directory paths with more flexible approach
- Uses `this.manifest.dir!` to determine plugin directory
- Supports better cross-platform and installation compatibility
- Removes static path references in multiple plugin components

Enhances plugin robustness by making directory paths more configurable
2025-09-05 17:56:56 +02:00
AlexKucera 05f28f84f3 Add Generic File embedding 2025-09-05 17:41:18 +02:00
AlexKucera 3cff3ff70a Renames plugin to "Typst PDF Export"
Updates the plugin's name from "Obsidian Typst PDF Export" to "Typst PDF Export".

This change simplifies the plugin's identifier and display name,
making it more concise and user-friendly. It involves updates to
the manifest file, plugin configuration, and references within the
codebase.
2025-09-05 16:57:23 +02:00
AlexKucera d40253e6c4 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.
2025-09-05 10:41:31 +02:00
AlexKucera 6ff1a24773 Removes excessive logging
Removes console log statements used for debugging during development, resulting in cleaner output and improved performance in production.
2025-09-04 22:48:55 +02:00
Jarvis 70241a012c feat: add PDF embedding and frontmatter display controls
- Add embedPdfFiles setting to control PDF attachment embedding
- Add printFrontmatter setting to display frontmatter as formatted text
- Implement frontmatter formatting with proper line breaks and bullet lists
- Add settings toggles to both plugin settings and export modal
- Fix filename sanitization for PDF preview images with spaces
- Ensure modal export config includes new behavior settings
- Always generate PDF preview images regardless of embedding setting

The frontmatter display formats long comma-separated values (like email lists)
as bulleted lists and adds proper line breaks after each property label.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 22:15:08 +02:00
AlexKucera a15caaef1e Adds type safety to process event handlers
Specifies the types for data and close events in process handlers.

This improves code clarity and maintainability by ensuring that the
data received from stdout and stderr streams is treated as a Buffer,
and the close event receives a number or null for the exit code.
2025-09-04 16:40:02 +02:00
AlexKucera 2c5b916978 Improves resource path caching error handling
Moves the catch block for resource path scanning to be inside the try block.
This ensures that errors during resource path caching do not prevent the timestamp from being updated, potentially leading to repeated scanning.
2025-09-04 16:38:02 +02:00
Jarvis 3fc6219ad1 WIP: Sharp removal changes 2025-09-04 16:32:12 +02:00
AlexKucera 1b3f83e6e6 Improves export performance with resource path caching
Implements a cache for resource paths to avoid rescanning the vault directory on every export.

This significantly improves the speed of subsequent exports,
especially when the vault contains a large number of files. The cache
expires after a configurable interval (default: 5 minutes) to ensure
that new or removed resources are eventually reflected.
2025-09-04 15:17:35 +02:00
AlexKucera 557a0675be Refactors file stat to use async API
Updates file stat operation to use the asynchronous API
to prevent blocking the event loop during file system operations.

This improves the responsiveness of the application, especially
when dealing with potentially slow or numerous file system accesses.
2025-09-04 15:03:43 +02:00
AlexKucera e48af55635 Adds robustness to file system operations
Improves error handling when creating directories,
loading, and saving settings. This prevents crashes and
provides more informative error messages to the user.

Adds a try-catch block to `fs.statSync` to handle cases where a
file might be deleted between `readdirSync` and `statSync`,
preventing program termination.
2025-09-03 23:09:36 +02:00
AlexKucera 3f8f2b2089 Refactors project structure for improved modularity
Moves components and modules to more appropriate directories.

This change improves project organization and maintainability by grouping related files into logical directories, enhancing code discoverability and reducing potential naming conflicts.
2025-09-03 22:05:45 +02:00
AlexKucera a2020c90f3 Introduces temp directory management
Centralizes temporary directory creation and cleanup using a dedicated `TempDirectoryManager` class.

This change improves code maintainability and reduces redundancy by encapsulating temporary directory logic.

It also ensures that temporary directories are properly cleaned up after export operations, preventing potential disk space issues.
2025-09-03 19:48:43 +02:00
AlexKucera 42ad862ba0 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.
2025-09-03 19:21:13 +02:00
Jarvis a0830e589b fix: correct unit handling for margins and font sizes in Typst export
- Add "cm" suffix to margin values (marginTop, marginBottom, marginLeft, marginRight) when passed from UI to Typst
- Add "pt" suffix to bodyFontSize values when passed from UI to Typst
- Remove obsolete heading_fontsize and small_fontsize parameters from templates
- Templates now use relative sizing (body-fontsize * multiplier) instead of separate font size variables

Fixes issue where Typst expected length units but received raw numbers, causing "expected relative length or auto, found float" errors during PDF export.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-03 17:02:28 +02:00
AlexKucera 26ddbb7f35 Enhances paper size selection and handling
Updates the paper size selection in settings and modals to use a predefined list of supported sizes, ensuring consistency across the plugin and compatibility with Typst.

It also maps the selected paper size to its Typst equivalent before passing it to the converter, preventing issues with unsupported sizes.
The change also ensures that template validation uses the correct paper sizes.
2025-09-03 14:35:34 +02:00
AlexKucera c749852125 Simplifies margin handling to use centimeters
Updates the margin settings to directly use centimeters, removing unnecessary conversions to points.
This simplifies the configuration and improves accuracy in setting page margins for PDF exports.
The settings tab and modal now accept and display margins in centimeters.
2025-09-03 13:59:35 +02:00
Jarvis 99da5f6cee fix: resolve export modal and PDF embed processing issues
- Fix font size duplication bug (11pt11pt) in exportFileWithConfig
- Fix modal settings not being respected by removing conditional fallbacks
- Fix Export Current Note to include complete template variables
- Fix PDF embed processing temp directory from system temp to plugin temp
- Fix pdf2img to use relative paths instead of absolute paths for proper file creation
- Ensure temp-images directory exists before PDF processing

The export modal now properly respects all user settings and PDF embeds
are correctly processed and found during export operations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-03 10:15:19 +02:00
Jarvis 172a69161d feat: refactor export system and improve PDF/email handling
Major improvements to PDF export functionality and code organization:

- BREAKING: Refactor main.ts from 4224 to 994 lines by extracting modular components
- Replace broken PDF links with proper Typst pdf.embed() attachments
- Filter out unnecessary "Open:" links and Mail.app links from exports
- Fix duplicate title issue by replacing frontmatter title with filename
- Move temp file processing from system temp to plugin folder
- Clean up temp-images and temp-pandoc directories after export
- Remove timestamp from export filenames to match note names exactly
- Handle Unicode line separators (0x2028, 0x2029) in email content
- Improve markdown preprocessing with better frontmatter handling

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-02 17:16:55 +02:00