Commit Graph
250 Commits
Author SHA1 Message Date
AlexKucera 39d66607af Merge pull request #7 from AlexKucera/windows_path_fix
Fixes path, image, and bibliography issues
2025-11-05 09:28:22 +01:00
AlexKucera 68238e3db2 Refines temp directory path validation
Ensures accurate determination of whether a directory is a temporary directory by explicitly matching the full path or a subdirectory.

This change prevents potential issues related to incorrect path comparisons, especially on Windows where path variations can occur.
2025-11-05 08:51:04 +01:00
AlexKucera c7b9a8b5b8 Fixes executable path resolution on Windows
Updates the executable path resolution logic to correctly identify executables on Windows systems by using the 'where' command instead of 'which', which is not available on Windows.

This change ensures that the application can locate and execute dependencies properly, regardless of the operating system. It also uses `path.isAbsolute` to accurately determine if a user-provided path is absolute, improving the reliability of path resolution.
2025-11-05 08:50:15 +01:00
AlexKucera 207e115699 Restricts shell metacharacters in paths
Addresses a potential command injection vulnerability by tightening the validation of executable paths.

Removes brackets and curly braces from the list of disallowed shell metacharacters in paths on Windows to prevent issues when paths contain these characters. Only the metacharacters that can't appear in safe paths are disallowed.
2025-11-05 08:47:35 +01:00
AlexKucera 35a5249607 Improves remote image download protocol handling
Ensures correct protocol (HTTP/HTTPS) is used when downloading
remote images by using the parsed URL object for the request.

This fixes potential issues where the protocol might be incorrectly
determined, especially when dealing with case-insensitive URL schemes.
2025-11-05 08:33:48 +01:00
AlexKucera a9f436f972 Simplifies path normalization for Windows compatibility
Avoids double normalization of paths, which can lead to issues with Windows path handling, specifically with drive letters and forward slashes.
2025-11-05 08:32:58 +01:00
AlexKucera c788422cdf Strengthens path validation against reserved names
Enhances path validation to prevent issues caused by reserved Windows names.

The previous implementation only checked for reserved names
when the entire path matched a reserved name. This update extends
the check to ensure that no segment of the path, including the
base name without extension, matches a reserved name.

This prevents the use of reserved names, even with extensions or
within directory structures, mitigating potential security risks.
2025-11-05 08:31:44 +01:00
AlexKucera a37e8e1e40 Fixes PATH handling for Windows compatibility
Ensures that the PATH environment variable is correctly augmented with
additional paths, especially on Windows systems. It uses platform-specific
path delimiters (';' on Windows, ':' on Unix) and filters out empty segments
to prevent PATH corruption.
2025-11-05 08:29:47 +01:00
AlexKucera 1aeebed4bf Ensures proper cleanup of converter resources
Addresses potential resource leaks by ensuring that temporary
files and event listeners are properly cleaned up when the
converter is disposed. This prevents issues with multiple
conversions, especially on platforms like Windows where file
locking can occur.

The `uncaughtException` handler is removed to avoid
swallowing errors, and a flag is added to prevent double
cleanup.
2025-11-05 08:28:35 +01:00
AlexKucera 4eb52d11c0 Handles relative redirects for remote images
Ensures that relative redirect URLs are resolved against the original image URL.
This prevents issues when downloading remote images from servers that return
relative redirect paths.
2025-11-05 08:06:48 +01:00
AlexKucera 711eab4593 Handles images without extensions correctly
Ensures images without file extensions are properly handled by appending ".png" to the filename, preventing potential issues with image processing or display.

Preserves existing extensions for other image types (e.g., svg, ico, avif) without forcing a ".png" extension.
2025-11-05 08:05:40 +01:00
AlexKucera 281c02210a Add Docstrings 2025-11-05 08:03:52 +01:00
AlexKucera 7ac9e1f489 Adds unit tests for core functionalities
Adds comprehensive unit tests to improve code coverage for core functionalities: constants, paper size mapping, modal settings, security utilities, temporary directory management, and variable mapping.

This ensures that basic functionalities work as expected and enhances the reliability of the plugin.

Additionally, this commit includes a mock Obsidian API to facilitate testing in a non-Obsidian environment.
2025-11-05 08:03:24 +01:00
AlexKucera 4a0376ec2b Simplifies path handling for temp directories
Removes unnecessary conditional logic when constructing paths for temporary directories.

The logic previously checked if the plugin directory was absolute before joining it with the directory name. This check is redundant as `path.join` correctly handles both absolute and relative paths.
2025-11-04 11:16:25 +01:00
AlexKucera 1ca3669e2f Ensures correct image download order
Ensures that standard markdown images with remote URLs are processed for download after embeds and before wikilinks.

This ensures that remote URLs in the standard markdown format `![](url)` are correctly queued for download.
2025-11-04 11:15:53 +01:00
AlexKucera 6e446048d2 Refactors local path resolution
Consolidates local path resolution logic into a dedicated
`resolveLocalPath` method for improved code reuse and readability.

Improves image downloading by using the vault adapter to write
binary data, preventing potential data corruption.

This change addresses issues with image embed resolution,
especially for attachments in non-standard locations, and fixes
file overwriting during image downloads.
2025-11-04 11:14:53 +01:00
AlexKucera 2e1d2673b1 Simplifies path joining logic
Simplifies the path joining logic by leveraging the built-in `path.join` method directly.
This change removes the manual iteration and absolute path handling, resulting in more concise and readable code.

Ensures correct path handling on Windows.
2025-11-04 11:10:53 +01:00
AlexKucera 501f380644 Simplifies path handling for Windows
Refactors the code to leverage `path.join` for cross-platform path manipulation, especially improving handling of absolute paths on Windows.

Removes redundant normalizations and simplifies the logic for determining temporary directories. This change ensures consistent behavior across different operating systems and reduces code complexity.
2025-11-04 11:09:47 +01:00
AlexKucera 9ca299cafd Fixes bibliography errors
Disables Pandoc's automatic citeproc filter to prevent errors
when processing documents without a bibliography file. This
resolves issues where Pandoc incorrectly detects citation-like
patterns in markdown and attempts to generate bibliographies,
leading to "document does not contain a bibliography" errors.
2025-11-04 10:57:24 +01:00
AlexKucera 8329c9dd48 Fixes path handling and adds remote image support
Addresses issues with path construction on Windows by using `path.isAbsolute()` to correctly handle absolute paths.  Improves cross-platform compatibility in temp directory management and binary location.

Adds support for downloading and embedding remote images (http/https URLs) in markdown, enhancing content integration. Provides fallback mechanism with placeholder text upon download failure.
2025-11-04 10:55:24 +01:00
AlexKucera 536351cbbf Updates repository URLs in README
Updates the repository URLs in the README file to reflect the correct owner.
This ensures users are directed to the correct location for the project and its releases, especially for installation instructions.
2025-09-26 07:47:35 +02:00
Jarvis 3f138f0b4b fix(FileDiscovery): Use PathUtils.getVaultPath() instead of adapter.basePath
Fixes TypeScript error by using the existing PathUtils.getVaultPath() method
which safely accesses FileSystemAdapter.getBasePath() with proper error handling.
The adapter.basePath property doesn't exist on DataAdapter interface.

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

Co-Authored-By: Claude <noreply@anthropic.com>
1.3.0
2025-09-25 16:50:36 +02:00
AlexKucera f1d545553b Merge pull request #5 from AlexKucera/1.3.0
Enhances path handling and file resolution
2025-09-25 16:47:12 +02:00
Jarvis ff8e9f9ea3 fix(PathUtils): Improve cross-platform absolute path detection
Replace complex heuristic with precise pattern matching for absolute paths:
- Unix paths: starts with /
- Windows drive letters: C:\ or C:/ using regex /^[a-zA-Z]:[/\\]/
- Windows UNC paths: \\server\share

Removes unreliable temp/tmp path indicators and file: URL checks while
maintaining fs fallback behavior for proper external file processing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:44:46 +02:00
Jarvis 21ed9e122f fix(FontManager): Improve cross-platform PATH handling and deduplication
- Set both PATH and Path environment variables for Windows compatibility
- Add tilde (~) path expansion for user home directories
- Implement actual path deduplication using Set instead of just filtering empty strings
- Properly split and combine existing PATH with additional platform-specific paths

Ensures spawned typst processes can find executables reliably across all platforms.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:41:27 +02:00
Jarvis 731a76eaf2 fix(FileDiscovery): Add vault path detection for safe adapter.list() usage
Prevents adapter.list() errors on absolute temp paths by detecting whether outputDir
is inside the vault and using filesystem fallback for external/absolute paths.
Only calls adapter.list() with vault-relative paths for proper Obsidian compatibility.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:39:08 +02:00
Jarvis 0cd6b53687 fix(BinaryLocator): Add filesystem fallback for validateBinaryExists when plugin unavailable
Improves binary validation by using fs.promises.access() as fallback when plugin context
is not available, ensuring cross-platform binary detection works reliably.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:37:10 +02:00
Jarvis e084ff38cb fix(TemplateManager): Convert absolute path to vault-relative for adapter.list()
- Fixed adapter.list() call to use vault-relative path instead of absolute templatesPath
- Added proper path conversion by stripping vault base path and leading separators
- Ensures compatibility with Obsidian's vault.adapter API requirements
- Prevents potential file listing failures due to incorrect path format
- Maintains cross-platform path handling with proper separator normalization

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:32:21 +02:00
Jarvis 97b356a912 fix(ExportOrchestrator): Add pluginName to TempDirectoryManager.create() for targeted cleanup
- Fixed TempDirectoryManager.create() to pass plugin.manifest.id instead of undefined
- Ensures temp directory cleanup targets only this plugin's directories
- Prevents interference with other plugins' temp directories
- Improves plugin isolation and cleanup reliability
- Follows proper plugin namespacing patterns established earlier

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:30:53 +02:00
Jarvis c4062d66b0 security(TempDirectoryManager): Fix path traversal vulnerability with normalized path comparison
- Replaced vulnerable string operations (startsWith/includes) with normalized path comparison
- Uses normalizePath() for proper cross-platform path normalization
- Constructs explicit temp directory paths for precise validation
- Prevents path traversal attacks like '../../../etc/passwd' or similar
- Ensures directory validation is based on actual path structure, not string matching
- Maintains functionality while improving security posture

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:29:54 +02:00
Jarvis 4e3ef6ce9c fix(PathUtils): Improve cross-platform absolute path detection without Node.js path module
- Replaced problematic heuristic path.includes('/') && !path.startsWith('.')
- Added explicit checks for Windows drive letters (C:), UNC paths, and Unix absolute paths
- Enhanced detection for temp directories and file URLs across platforms
- Maintains Obsidian API-first approach without importing Node.js path module
- Better handles Windows absolute paths like 'C:\Users\...' and '\UNC\paths'
- Preserves existing fs.access fallback behavior for external files

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:26:11 +02:00
Jarvis d54ac148c0 fix(ImageOptimizer): Convert absolute paths to vault-relative for adapter.remove()
- Fixed vault.adapter.remove() call to use vault-relative paths instead of absolute paths
- Added proper path conversion by stripping vault base path and leading separators
- Maintains fs.unlink fallback when plugin.app is not available
- Prevents potential file removal failures due to incorrect path format
- Follows Obsidian API best practices for vault operations

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:23:54 +02:00
AlexKucera a1293808af Fixes CodeRabbit badge URL
Corrects the CodeRabbit badge URL in the README.
2025-09-25 16:19:48 +02:00
Jarvis 2cdc9c3976 docs(CHANGELOG): Add comprehensive 1.3.1 release notes
- Documents all CodeRabbit review improvements implemented
- Highlights Windows compatibility enhancements
- Details dynamic image format support and pattern matching
- Records cross-platform font discovery improvements
- Notes security and path validation enhancements
- Organizes changes by Added/Fixed/Changed/Security categories

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:12:32 +02:00
Jarvis 0a409076c3 feat(FontManager): Improve path consistency and cross-platform font discovery
- Fixed vault.adapter operations to use vault-relative paths instead of absolute paths
- Added platform detection to cache data for invalidation on OS changes
- Enhanced error recovery with corrupted cache detection and automatic regeneration
- Improved cache validation with structure and content checks
- Added platform-specific PATH building for better Typst executable discovery
- Enhanced Windows, macOS, and Linux font path resolution
- Added comprehensive fallback mechanisms for all error scenarios
- Improved type safety and error handling throughout

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:10:28 +02:00
Jarvis a22bd06b7b fix(ExportOrchestrator): Add plugin namespacing to TempDirectoryManager
- Added pluginName parameter using manifest.id for proper temp directory namespacing
- Improves isolation when multiple similar plugins are installed
- Prevents temp directory conflicts between plugins
- Uses existing TempDirectoryOptions.pluginName field per CodeRabbit review

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:07:20 +02:00
Jarvis 0cc96e9345 feat(FileDiscovery): Add dynamic image extension support with enhanced pattern matching
- Added support for multiple image formats (.png, .jpg, .jpeg, .webp, .gif, .bmp, .tiff)
- Replaced hardcoded PNG-only filtering with dynamic extension detection
- Enhanced pattern matching with 5 progressive strategies:
  1. Exact filename match
  2. Base name match with any supported extension
  3. Sanitized pattern match (removes special characters)
  4. Fuzzy match for pdf2img patterns (handles -1, -page1 suffixes)
  5. Fallback to first available image file
- Updated generateExpectedFilename with format validation and warnings
- Improved error messages to show supported formats and available files

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:06:00 +02:00
Jarvis 24a169d490 feat(BinaryLocator): Add Windows compatibility with platform-specific binary detection
- Added support for Windows executable extensions (.cmd, .bat, .ps1, .exe)
- Implemented comprehensive fallback paths for different installation methods
- Enhanced binary discovery with Windows-specific npm locations
- Improved error reporting with detailed search path information
- Maintains backward compatibility for Unix-like systems

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:01:28 +02:00
AlexKucera d20e8cf0ae Adds CodeRabbit Reviews badge to README
Includes a CodeRabbit Reviews badge in the README to provide quick access to code review insights.
2025-09-25 15:37:19 +02:00
Jarvis b47571dccd fix(ResourcePathResolver): Use vault-relative paths for adapter.list()
- Changed adapter.list() to use empty string for vault root instead of absolute path
- Convert vault-relative paths to absolute paths when returning for external tools
- Fixes cross-platform compatibility issues per CodeRabbit review
- Maintains existing functionality while following Obsidian API best practices

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 13:45:57 +02:00
Jarvis 3782f0a7fb fix: remove extra quotes from pandoc resource path arguments
- Remove manual quotes around templatesDir path in PandocCommandBuilder
- Node.js spawn() handles argument quoting automatically
- Manual quotes can break path resolution, especially on Windows
- Follows Node.js best practices for child_process.spawn()

CodeRabbit suggestion implementation 1/6
2025-09-25 13:43:13 +02:00
Jarvis c971c920ce chore: release 1.3.0 2025-09-25 12:46:54 +02:00
Jarvis 37015c8ed6 fix: resolve embedded file path resolution issue in PathUtils.fileExists
- Fix pathUtils.fileExists() to handle absolute filesystem paths
- Add proper conversion from absolute to vault-relative paths
- Add fs fallback for external files outside vault
- Resolves 'File not found' errors for embedded PDF, image, and document files
- Maintains compatibility with both vault-relative and absolute paths

This fixes the path resolution issue that occurred after migrating to vault.adapter,
where embedded files were showing as 'not found' because absolute paths were being
passed to vault.adapter.exists() which only accepts vault-relative paths.
2025-09-25 12:43:00 +02:00
Jarvis 0ff5b4a1b8 refactor: migrate embeddedTemplates.ts to use PathUtils and vault.adapter
- Replace fs operations with vault.adapter methods
- Update constructor to require App parameter
- Make all methods async for vault.adapter compatibility
- Update PluginLifecycle.ts to match new async API
- Remove direct fs/path module dependencies
- Build and lint pass successfully

Safety commit 16/16 - Path migration complete!
2025-09-25 12:39:54 +02:00
Jarvis b6f64d1cf7 refactor: migrate ImageOptimizer.ts to use vault.adapter
- Replace fs.unlink/rename with vault.adapter methods when plugin available
- Replace path.join with PathUtils.joinPath for vault paths
- Add plugin parameter to optimizeImage method for vault.adapter access
- Keep path module for external tool operations
- Add fs fallbacks for temp file operations when plugin unavailable
- Use readBinary/writeBinary pattern for image file moves
- Update PdfToImageConverter.ts to pass plugin to ImageOptimizer
- Maintain dual approach for vault and external temp file handling
2025-09-25 12:35:45 +02:00
Jarvis 497407e288 refactor: migrate FileDiscovery.ts to use vault.adapter
- Replace fs.access/readdir with vault.adapter methods
- Replace path.join with PathUtils.joinPath for vault paths
- Add plugin parameter to methods for vault.adapter access
- Keep path module for basename operations on external files
- Add fs fallback when plugin unavailable (external tool output)
- Update PdfToImageConverter.ts to pass plugin to FileDiscovery
- Maintain dual approach for vault and external file discovery
2025-09-25 12:30:25 +02:00
Jarvis ee79ed3f74 refactor: migrate ResourcePathResolver.ts to use vault.adapter
- Replace all fs operations with vault.adapter methods
- Replace fs.readdirSync with vault.adapter.list for directory scanning
- Replace fs.existsSync with PathUtils.fileExists
- Replace path.join with PathUtils.joinPath for vault paths
- Remove fs/fsPromises imports, add PathUtils import
- Add plugin parameter to constructor for vault.adapter access
- Update PandocCommandBuilder to pass plugin to ResourcePathResolver
- Maintain resource discovery functionality for Pandoc
2025-09-25 12:27:33 +02:00
Jarvis f8142f995a refactor: migrate PandocCommandBuilder.ts to use PathUtils
- Replace fs.existsSync with PathUtils.fileExists()
- Replace path.resolve with PathUtils.joinPath() for vault paths
- Remove fs require, add PathUtils import
- Keep path module for external tool relative path operations (path.relative)
- Follow plan guidance for minimal path usage with external tools
2025-09-25 12:25:25 +02:00
Jarvis 948ec77ae6 refactor: migrate PdfToImageConverter.ts to use vault.adapter
- Replace fs.mkdir with PathUtils.ensureDir()
- Remove fs/promises import
- Keep path module for external PDF file basename extraction
- Add null check for plugin.app availability
- Follow plan guidance for minimal path usage with external files
2025-09-25 12:24:18 +02:00
Jarvis 121fc0a75c refactor: migrate PandocTypstConverter.ts to use PathUtils
- Replace fs.promises operations with vault.adapter methods
- Replace path.join with PathUtils.joinPath for temp file paths
- Replace fsPromises.writeFile/unlink with vault.adapter.write/remove
- Replace fsPromises.rmdir with PathUtils.cleanupDir
- Remove unused path and os imports
- Use TempDirectoryManager consistently for both fallback cases
2025-09-25 12:22:54 +02:00