From b9fb1a455f9b36b3e1035cc7763e12af98ef19ba Mon Sep 17 00:00:00 2001 From: Jarvis Date: Sun, 31 Aug 2025 14:39:57 +0200 Subject: [PATCH] feat: add PDF embed support with first-page preview generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement PdfToImageConverter using pdf-to-img CLI for PDF-to-image conversion - Add PDF embed detection and processing in MarkdownPreprocessor - Generate first-page preview images for PDF embeds in exported documents - Copy generated images to vault location for Typst accessibility - Add --embed-resources flag to Pandoc for proper resource embedding - Support both image and PDF attachments in exported documents Fixes issue where PDF exports only contained text without attachments. PDF embeds now show visual previews like Obsidian's native behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- main.ts | 226 ++++++++- package-lock.json | 971 ++++++++++++++++++++++++++++++++++-- package.json | 3 +- src/MarkdownPreprocessor.ts | 35 +- src/PdfToImageConverter.ts | 299 +++++++++++ src/template-manager.ts | 331 ++++-------- templates/article.typ | 89 ++++ templates/default.typ | 69 +++ templates/report.typ | 98 ++++ templates/single-page.typ | 87 ++++ 10 files changed, 1943 insertions(+), 265 deletions(-) create mode 100644 src/PdfToImageConverter.ts create mode 100644 templates/article.typ create mode 100644 templates/default.typ create mode 100644 templates/report.typ create mode 100644 templates/single-page.typ diff --git a/main.ts b/main.ts index 0d61c02..2a7ecc8 100644 --- a/main.ts +++ b/main.ts @@ -134,6 +134,82 @@ class PandocTypstConverter { process.on('uncaughtException', cleanup); } + /** + * Process PDF embeds by converting them to images and creating combined output + */ + private async processPdfEmbeds(processedResult: any, vaultBasePath: string, tempDir: string): Promise { + const { PdfToImageConverter } = require('./src/PdfToImageConverter'); + const converter = PdfToImageConverter.getInstance(); + const path = require('path'); + + for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { + try { + console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`); + + // Resolve full path to the PDF + const fullPdfPath = path.resolve(vaultBasePath, pdfEmbed.sanitizedPath); + + // Check if PDF file exists + const fs = require('fs'); + if (!fs.existsSync(fullPdfPath)) { + console.warn(`Export: PDF file not found: ${fullPdfPath}`); + // Replace marker with error message + processedResult.content = processedResult.content.replace( + pdfEmbed.marker, + `[⚠️ PDF not found: ${pdfEmbed.fileName}](${pdfEmbed.sanitizedPath})` + ); + continue; + } + + // Convert PDF to image + const conversionResult = await converter.convertFirstPageToImage( + fullPdfPath, + tempDir, + { + scale: 1.5, + maxWidth: 600, + maxHeight: 400, + format: 'png' + } + ); + + if (conversionResult.success) { + // Get relative path for the generated image + const relativeImagePath = path.relative(vaultBasePath, conversionResult.imagePath); + + // Create combined output: image preview + PDF attachment link + const combinedOutput = [ + `![${pdfEmbed.fileName} - Page 1](${relativeImagePath})`, + `[📎 **Download PDF:** ${pdfEmbed.fileName}](${pdfEmbed.sanitizedPath})` + ].join('\n\n'); + + // Replace marker with combined output + processedResult.content = processedResult.content.replace(pdfEmbed.marker, combinedOutput); + + console.log(`Export: Successfully converted PDF: ${pdfEmbed.fileName} -> ${path.basename(conversionResult.imagePath)}`); + + } else { + console.error(`Export: PDF conversion failed: ${conversionResult.error}`); + + // Replace marker with fallback link + processedResult.content = processedResult.content.replace( + pdfEmbed.marker, + `[📖 ${pdfEmbed.fileName}](${pdfEmbed.sanitizedPath})\n\n*Note: PDF preview could not be generated*` + ); + } + + } catch (error) { + console.error(`Export: Error processing PDF embed: ${error.message}`); + + // Replace marker with error fallback + processedResult.content = processedResult.content.replace( + pdfEmbed.marker, + `[⚠️ ${pdfEmbed.fileName}](${pdfEmbed.sanitizedPath})\n\n*Error: Could not process PDF embed*` + ); + } + } + } + /** * Clean up temporary files and directories */ @@ -190,6 +266,9 @@ if (this.pandocOptions.typstPath) { // Enable standalone mode (required for PDF output) args.push('--standalone'); +// Embed resources (images, etc.) directly into the output +args.push('--embed-resources'); + // Add resource paths for attachment resolution if (this.pandocOptions.vaultBasePath) { const path = require('path'); @@ -225,7 +304,7 @@ if (this.pandocOptions.vaultBasePath) { // Check if this directory contains images try { const dirContents = fs.readdirSync(itemPath); - const hasImages = dirContents.some(file => + const hasImages = dirContents.some((file: string) => /\.(png|jpg|jpeg|gif|svg|webp|bmp|ico|tiff)$/i.test(file) ); if (hasImages) { @@ -1356,12 +1435,18 @@ try { console.warn('Preprocessing warnings:', processedResult.warnings); } + // Process PDF embeds if any were found + if (processedResult.metadata.pdfEmbeds && processedResult.metadata.pdfEmbeds.length > 0) { + console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`); + await this.processPdfEmbeds(processedResult, vaultBasePath, tempDir, file); + } + // Debug: Log processed content to see what image paths look like console.log('Export: Original content length:', content.length); console.log('Export: Processed content length:', processedResult.content.length); // Log a sample of processed content to see image references - const imageSample = processedResult.content.split('\n').filter(line => + const imageSample = processedResult.content.split('\n').filter((line: string) => line.includes('![') || line.includes(' { + const { PdfToImageConverter } = require('./src/PdfToImageConverter'); + const converter = PdfToImageConverter.getInstance(); + const path = require('path'); + const fs = require('fs'); + + console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`); + + let updatedContent = processedResult.content; + + for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { + try { + console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`); + + // Decode the URL-encoded sanitized path back to normal characters + const decodedPath = decodeURIComponent(pdfEmbed.sanitizedPath); + + // Try multiple path resolution strategies + const possiblePaths = [ + // Strategy 1: Relative to vault root (standard Obsidian behavior) + path.resolve(vaultBasePath, decodedPath), + // Strategy 2: Relative to current file's directory (for local attachments) + currentFile ? path.resolve(vaultBasePath, path.dirname(currentFile.path), decodedPath) : null + ].filter(p => p !== null); + + let fullPdfPath = null; + let validPath = null; + + // Try each possible path until we find one that exists + for (const possiblePath of possiblePaths) { + console.log(`Export: Checking path: ${possiblePath}`); + if (fs.existsSync(possiblePath)) { + fullPdfPath = possiblePath; + validPath = possiblePath; + console.log(`Export: Found PDF at: ${fullPdfPath}`); + break; + } + } + + if (!fullPdfPath) { + console.warn(`Export: PDF file not found in any of the expected locations: ${possiblePaths.join(', ')}`); + // Replace marker with fallback link + const fallbackOutput = `[⚠️ **PDF not found:** ${pdfEmbed.baseName}](${decodedPath})`; + updatedContent = updatedContent.replace(pdfEmbed.marker, fallbackOutput); + continue; + } + + // Convert PDF first page to image + const result = await converter.convertFirstPageToImage( + fullPdfPath, + tempDir, + { + scale: 1.5, + maxWidth: 800, + maxHeight: 600, + format: 'png' + } + ); + + if (result.success) { + // Create a temporary images directory within the vault for Typst access + const vaultTempImagesDir = path.join(vaultBasePath, '.obsidian', 'plugins', 'obsidian-typst-pdf-export', 'temp-images'); + const fs_promises = require('fs').promises; + await fs_promises.mkdir(vaultTempImagesDir, { recursive: true }); + + // Copy the image from temp directory to vault temp directory + const originalImageName = path.basename(result.imagePath); + const vaultImagePath = path.join(vaultTempImagesDir, originalImageName); + await fs_promises.copyFile(result.imagePath, vaultImagePath); + + // Get relative path for the generated image from vault base + const relativeImagePath = path.relative(vaultBasePath, vaultImagePath); + + // Use relative path to the original PDF from vault base for download link + const relativePdfPath = path.relative(vaultBasePath, validPath); + + // Create combined output: image preview + download link + const combinedOutput = [ + `![${pdfEmbed.baseName} - Page 1](${relativeImagePath})`, + '', + `[📎 **Download PDF:** ${pdfEmbed.baseName}](${relativePdfPath})` + ].join('\n'); + + // Replace the placeholder with the combined output + updatedContent = updatedContent.replace(pdfEmbed.marker, combinedOutput); + + console.log(`Export: Successfully processed PDF embed: ${pdfEmbed.baseName}`); + } else { + console.error(`Export: Failed to convert PDF: ${result.error}`); + // Replace with download link only + const relativePdfPath = path.relative(vaultBasePath, validPath); + const fallbackOutput = `[📎 **Download PDF:** ${pdfEmbed.baseName}](${relativePdfPath})`; + updatedContent = updatedContent.replace(pdfEmbed.marker, fallbackOutput); + } + } catch (error) { + console.error(`Export: Error processing PDF embed ${pdfEmbed.baseName}:`, error); + // Replace with download link only as fallback + const decodedPath = decodeURIComponent(pdfEmbed.sanitizedPath); + const fallbackOutput = `[📎 **Download PDF:** ${pdfEmbed.baseName}](${decodedPath})`; + updatedContent = updatedContent.replace(pdfEmbed.marker, fallbackOutput); + } + } + + // Update the processed result with the new content + processedResult.content = updatedContent; + } } /** diff --git a/package-lock.json b/package-lock.json index 1e7895a..a760d16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "gray-matter": "^4.0.3" + "gray-matter": "^4.0.3", + "pdf-to-img": "^4.5.0" }, "devDependencies": { "@types/node": "^16.11.6", @@ -529,6 +530,27 @@ "license": "BSD-3-Clause", "peer": true }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", + "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==", + "license": "BSD-3-Clause", + "optional": true, + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, "node_modules/@marijn/find-cluster-break": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz", @@ -816,6 +838,13 @@ "license": "ISC", "peer": true }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "license": "ISC", + "optional": true + }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", @@ -841,6 +870,19 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "optional": true, + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -863,9 +905,8 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, + "devOptional": true, "license": "MIT", - "peer": true, "engines": { "node": ">=8" } @@ -887,6 +928,28 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/aproba": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.1.0.tgz", + "integrity": "sha512-tLIEcj5GuR2RSTnxNKdkK0dJ/GrC7P38sUkiDmDuHfsHmbagTFAxDVIBltoklXEVIQ/f14IL8IMJ5pn9Hez1Ew==", + "license": "ISC", + "optional": true + }, + "node_modules/are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "optional": true, + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -909,17 +972,46 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true, + "devOptional": true, + "license": "MIT" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", "license": "MIT", - "peer": true + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } }, "node_modules/brace-expansion": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", - "dev": true, + "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -938,6 +1030,30 @@ "node": ">=8" } }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, "node_modules/builtin-modules": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", @@ -962,6 +1078,20 @@ "node": ">=6" } }, + "node_modules/canvas": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-3.1.0.tgz", + "integrity": "sha512-tTj3CqqukVJ9NgSahykNwtGda7V33VLObwrHfzT0vqJXu7J4d4C/7kQQW3fOEGDfZZoILPut5H00gOjyttPGyg==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-addon-api": "^7.0.0", + "prebuild-install": "^7.1.1" + }, + "engines": { + "node": "^18.12.0 || >= 20.9.0" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -980,6 +1110,12 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/chownr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", + "license": "ISC" + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1002,13 +1138,29 @@ "license": "MIT", "peer": true }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "license": "ISC", + "optional": true, + "bin": { + "color-support": "bin.js" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true, - "license": "MIT", - "peer": true + "devOptional": true, + "license": "MIT" + }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==", + "license": "ISC", + "optional": true }, "node_modules/crelt": { "version": "1.0.6", @@ -1038,7 +1190,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -1052,6 +1204,30 @@ } } }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "license": "MIT", + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -1060,6 +1236,22 @@ "license": "MIT", "peer": true }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", + "license": "MIT", + "optional": true + }, + "node_modules/detect-libc": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz", + "integrity": "sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -1087,6 +1279,22 @@ "node": ">=6.0.0" } }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT", + "optional": true + }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, "node_modules/esbuild": { "version": "0.17.3", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.3.tgz", @@ -1383,6 +1591,15 @@ "node": ">=0.10.0" } }, + "node_modules/expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", + "license": "(MIT OR WTFPL)", + "engines": { + "node": ">=6" + } + }, "node_modules/extend-shallow": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", @@ -1528,13 +1745,44 @@ "license": "ISC", "peer": true }, + "node_modules/fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "license": "MIT" + }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "license": "ISC", + "optional": true, + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "license": "ISC", + "optional": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true, - "license": "ISC", - "peer": true + "devOptional": true, + "license": "ISC" }, "node_modules/functional-red-black-tree": { "version": "1.0.1", @@ -1543,14 +1791,41 @@ "dev": true, "license": "MIT" }, + "node_modules/gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "optional": true, + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", + "license": "MIT" + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "deprecated": "Glob versions prior to v9 are no longer supported", - "dev": true, + "devOptional": true, "license": "ISC", - "peer": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -1674,6 +1949,47 @@ "node": ">=8" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", + "license": "ISC", + "optional": true + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "optional": true, + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -1718,9 +2034,8 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, + "devOptional": true, "license": "ISC", - "peer": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -1730,9 +2045,13 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true, - "license": "ISC", - "peer": true + "license": "ISC" + }, + "node_modules/ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "license": "ISC" }, "node_modules/is-extendable": { "version": "0.1.1", @@ -1753,6 +2072,16 @@ "node": ">=0.10.0" } }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=8" + } + }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -1893,6 +2222,32 @@ "license": "MIT", "peer": true }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "license": "MIT", + "optional": true, + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", + "optional": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -1917,13 +2272,24 @@ "node": ">=8.6" } }, + "node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, + "devOptional": true, "license": "ISC", - "peer": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -1931,6 +2297,71 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "license": "ISC", + "optional": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "license": "MIT", + "optional": true, + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "license": "ISC", + "optional": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "license": "MIT", + "optional": true, + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", + "license": "MIT" + }, "node_modules/moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", @@ -1945,7 +2376,20 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, + "devOptional": true, + "license": "MIT" + }, + "node_modules/nan": { + "version": "2.23.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.23.0.tgz", + "integrity": "sha512-1UxuyYGdoQHcGg87Lkqm3FzefucTa0NAiOcuRsDmysep3c1LVCRK2krrUDafMWtjSG04htvAmvg96+SDknOmgQ==", + "license": "MIT", + "optional": true + }, + "node_modules/napi-build-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", + "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", "license": "MIT" }, "node_modules/natural-compare": { @@ -1956,6 +2400,85 @@ "license": "MIT", "peer": true }, + "node_modules/node-abi": { + "version": "3.75.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.75.0.tgz", + "integrity": "sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==", + "license": "MIT", + "dependencies": { + "semver": "^7.3.5" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-addon-api": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "license": "MIT" + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "optional": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "license": "ISC", + "optional": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "optional": true, + "dependencies": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/obsidian": { "version": "1.8.7", "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.8.7.tgz", @@ -1975,9 +2498,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "license": "ISC", - "peer": true, "dependencies": { "wrappy": "1" } @@ -2064,9 +2585,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, + "devOptional": true, "license": "MIT", - "peer": true, "engines": { "node": ">=0.10.0" } @@ -2092,6 +2612,99 @@ "node": ">=8" } }, + "node_modules/path2d": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/path2d/-/path2d-0.2.2.tgz", + "integrity": "sha512-+vnG6S4dYcYxZd+CZxzXCNKdELYZSKfohrk98yajCo1PtRoDgCTrrwOvK1GT0UoAdVszagDVllQc0U1vaX4NUQ==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/pdf-to-img": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/pdf-to-img/-/pdf-to-img-4.5.0.tgz", + "integrity": "sha512-GCM2n+aYiupQmyoOmuj/0Q3Tr0hJg9iFVGiOq79y1ePF2cTGzdbPFd3lNlH1IxvqcGgQzwyo7KfNvtmefBxIiQ==", + "license": "MIT", + "dependencies": { + "canvas": "3.1.0", + "pdfjs-dist": "4.2.67" + }, + "bin": { + "pdf2img": "bin/cli.mjs" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/pdfjs-dist": { + "version": "4.2.67", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.2.67.tgz", + "integrity": "sha512-rJmuBDFpD7cqC8WIkQUEClyB4UAH05K4AsyewToMTp2gSy3Rrx8c1ydAVqlJlGv3yZSOrhEERQU/4ScQQFlLHA==", + "license": "Apache-2.0", + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "canvas": "^2.11.2", + "path2d": "^0.2.0" + } + }, + "node_modules/pdfjs-dist/node_modules/canvas": { + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.11.2.tgz", + "integrity": "sha512-ItanGBMrmRV7Py2Z+Xhs7cT+FNt5K0vPL4p9EZ/UX/Mu7hFbkxSjKF2KVtPwX7UYWp7dRKnrTvReflgrItJbdw==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.0", + "nan": "^2.17.0", + "simple-get": "^3.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/pdfjs-dist/node_modules/decompress-response": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz", + "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==", + "license": "MIT", + "optional": true, + "dependencies": { + "mimic-response": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/pdfjs-dist/node_modules/mimic-response": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", + "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/pdfjs-dist/node_modules/simple-get": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz", + "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==", + "license": "MIT", + "optional": true, + "dependencies": { + "decompress-response": "^4.2.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -2105,6 +2718,32 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/prebuild-install": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", + "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", + "license": "MIT", + "dependencies": { + "detect-libc": "^2.0.0", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^2.0.0", + "node-abi": "^3.3.0", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^4.0.0", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0" + }, + "bin": { + "prebuild-install": "bin.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -2116,6 +2755,16 @@ "node": ">= 0.8.0" } }, + "node_modules/pump": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz", + "integrity": "sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -2148,6 +2797,44 @@ ], "license": "MIT" }, + "node_modules/rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", + "dependencies": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "bin": { + "rc": "cli.js" + } + }, + "node_modules/rc/node_modules/strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -2188,9 +2875,8 @@ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "deprecated": "Rimraf versions prior to v4 are no longer supported", - "dev": true, + "devOptional": true, "license": "ISC", - "peer": true, "dependencies": { "glob": "^7.1.3" }, @@ -2225,6 +2911,26 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/section-matter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz", @@ -2242,7 +2948,6 @@ "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -2251,6 +2956,13 @@ "node": ">=10" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "license": "ISC", + "optional": true + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -2276,6 +2988,58 @@ "node": ">=8" } }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "license": "ISC", + "optional": true + }, + "node_modules/simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/simple-get": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", + "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -2292,13 +3056,36 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "license": "BSD-3-Clause" }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "optional": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, + "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -2351,6 +3138,62 @@ "node": ">=8" } }, + "node_modules/tar": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", + "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", + "license": "ISC", + "optional": true, + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar-fs": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.3.tgz", + "integrity": "sha512-090nwYJDmlhwFwEW3QQl+vaNnxsO2yVsd45eTKRBzSzu+hlb1w2K9inVq5b0ngXuLVqQ4ApvsUHHnu/zQNkWAg==", + "license": "MIT", + "dependencies": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "node_modules/tar-stream": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "license": "MIT", + "dependencies": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tar/node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "license": "ISC", + "optional": true, + "engines": { + "node": ">=10" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -2372,6 +3215,13 @@ "node": ">=8.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT", + "optional": true + }, "node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -2402,6 +3252,18 @@ "dev": true, "license": "0BSD" }, + "node_modules/tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + }, + "engines": { + "node": "*" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -2455,6 +3317,12 @@ "punycode": "^2.1.0" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, "node_modules/w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", @@ -2463,6 +3331,24 @@ "license": "MIT", "peer": true }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause", + "optional": true + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "optional": true, + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -2480,6 +3366,16 @@ "node": ">= 8" } }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "license": "ISC", + "optional": true, + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -2495,9 +3391,14 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true, + "license": "ISC" + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "license": "ISC", - "peer": true + "optional": true }, "node_modules/yocto-queue": { "version": "0.1.0", diff --git a/package.json b/package.json index 13b291f..87f97a8 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "typescript": "4.7.4" }, "dependencies": { - "gray-matter": "^4.0.3" + "gray-matter": "^4.0.3", + "pdf-to-img": "^4.5.0" } } diff --git a/src/MarkdownPreprocessor.ts b/src/MarkdownPreprocessor.ts index b64b6da..0d30cf6 100644 --- a/src/MarkdownPreprocessor.ts +++ b/src/MarkdownPreprocessor.ts @@ -28,6 +28,14 @@ export interface PreprocessingResult { frontmatter?: Record; title?: string; wordCount: number; + pdfEmbeds?: Array<{ + originalPath: string; + sanitizedPath: string; + fileName: string; + baseName: string; + options?: string; + marker: string; + }>; }; /** Processing errors and warnings */ errors: string[]; @@ -504,16 +512,35 @@ export class MarkdownPreprocessor { } /** - * Process PDF embeds + * Process PDF embeds - Convert to image preview with PDF attachment */ private processPdfEmbed(pdfPath: string, options: string | undefined, result: PreprocessingResult): string { const sanitizedPath = this.sanitizeFilePath(pdfPath); - // PDFs can be handled similarly to documents + // For now, we'll mark this for async processing and return a placeholder + // The actual conversion will be handled in the main export process const fileName = pdfPath.substring(pdfPath.lastIndexOf('/') + 1); - result.warnings.push(`PDF embed converted to link: ${pdfPath}`); + const baseName = fileName.replace(/\.[^/.]+$/, ""); // Remove extension - return `[📖 ${fileName}](${sanitizedPath})`; + // Create a marker that the export process can detect and replace + const marker = `PDF_EMBED_MARKER:${pdfPath}:${baseName}:${options || ''}`; + + // Add to processing queue for later conversion + if (!result.metadata.pdfEmbeds) { + result.metadata.pdfEmbeds = []; + } + result.metadata.pdfEmbeds.push({ + originalPath: pdfPath, + sanitizedPath: sanitizedPath, + fileName: fileName, + baseName: baseName, + options: options, + marker: marker + }); + + result.warnings.push(`PDF embed queued for image conversion: ${pdfPath}`); + + return marker; } /** diff --git a/src/PdfToImageConverter.ts b/src/PdfToImageConverter.ts new file mode 100644 index 0000000..2b4086e --- /dev/null +++ b/src/PdfToImageConverter.ts @@ -0,0 +1,299 @@ +/** + * PDF to Image Converter using pdf-to-img + * Converts PDF files to PNG images for preview in Typst exports + */ + +import * as fs from 'fs/promises'; +import * as path from 'path'; + +export interface PdfConversionOptions { + /** Quality/scale factor for the rendered image (default: 2.0 for HiDPI) */ + scale?: number; + /** Maximum width in pixels (default: 800) */ + maxWidth?: number; + /** Maximum height in pixels (default: 600) */ + maxHeight?: number; + /** Output format (default: 'png') */ + format?: 'png' | 'jpeg'; + /** JPEG quality if using jpeg format (default: 90) */ + quality?: number; +} + +export interface PdfConversionResult { + /** Path to the generated image file */ + imagePath: string; + /** Original PDF dimensions */ + originalDimensions: { + width: number; + height: number; + }; + /** Generated image dimensions */ + imageDimensions: { + width: number; + height: number; + }; + /** Success status */ + success: boolean; + /** Error message if conversion failed */ + error?: string; +} + +export class PdfToImageConverter { + private static instance: PdfToImageConverter; + + private constructor() {} + + public static getInstance(): PdfToImageConverter { + if (!PdfToImageConverter.instance) { + PdfToImageConverter.instance = new PdfToImageConverter(); + } + return PdfToImageConverter.instance; + } + + /** + * Convert the first page of a PDF to an image + */ + public async convertFirstPageToImage( + pdfPath: string, + outputDir: string, + options: PdfConversionOptions = {} + ): Promise { + try { + // Set default options + const opts: Required = { + scale: options.scale || 2.0, + maxWidth: options.maxWidth || 800, + maxHeight: options.maxHeight || 600, + format: options.format || 'png', + quality: options.quality || 90 + }; + + // Ensure the PDF file exists + try { + await fs.access(pdfPath); + } catch (error) { + return { + imagePath: '', + originalDimensions: { width: 0, height: 0 }, + imageDimensions: { width: 0, height: 0 }, + success: false, + error: `PDF file not found: ${pdfPath}` + }; + } + + // Ensure output directory exists + await fs.mkdir(outputDir, { recursive: true }); + + // Generate output file name for the first page + const pdfBaseName = path.basename(pdfPath, path.extname(pdfPath)); + // pdf2img uses the pattern: "filename-1.png" for first page + const expectedOutputFileName = `${pdfBaseName}-1.png`; + const expectedOutputPath = path.join(outputDir, expectedOutputFileName); + + // Use the CLI to convert PDF to images + const { exec } = require('child_process'); + const { promisify } = require('util'); + const execAsync = promisify(exec); + + // Get the plugin directory - need to handle Obsidian's environment + // In Obsidian, __dirname points to electron.asar, so we need to find the actual plugin path + let pluginDir: string; + + // Try multiple strategies to find the plugin directory + const possiblePluginDirs = [ + // Strategy 1: From process.cwd() if it's in the vault + path.join(process.cwd(), '.obsidian', 'plugins', 'obsidian-typst-pdf-export'), + // Strategy 2: Assuming we're running from vault root + path.join('.obsidian', 'plugins', 'obsidian-typst-pdf-export'), + // Strategy 3: Direct path if running in development + '/Users/alex/Obsidian/Dev/.obsidian/plugins/obsidian-typst-pdf-export' + ]; + + // Find the first directory that exists and has node_modules + pluginDir = possiblePluginDirs.find(dir => { + try { + const nodeModulesPath = path.join(dir, 'node_modules'); + return require('fs').existsSync(nodeModulesPath); + } catch { + return false; + } + }) || possiblePluginDirs[0]; // Fallback to first option + + const pdf2imgPath = path.join(pluginDir, 'node_modules', '.bin', 'pdf2img'); + + console.log(`Plugin directory: ${pluginDir}`); + console.log(`PDF2IMG path: ${pdf2imgPath}`); + + // Check if the binary exists + const fs2 = require('fs'); + if (!fs2.existsSync(pdf2imgPath)) { + return { + imagePath: '', + originalDimensions: { width: 0, height: 0 }, + imageDimensions: { width: 0, height: 0 }, + success: false, + error: `PDF2IMG binary not found at: ${pdf2imgPath}` + }; + } + + // Build the CLI command - the pdf2img binary is already executable + const cliCommand = [ + `"${pdf2imgPath}"`, + `"${pdfPath}"`, + '--scale', opts.scale.toString(), + '--output', `"${outputDir}"`, + '--pages', '1' // Only convert the first page + ].join(' '); + + console.log(`PDF conversion command: ${cliCommand}`); + + try { + // Set environment variables to ensure node can be found + const env = { + ...process.env, + PATH: process.env.PATH + ':/opt/homebrew/bin:/usr/local/bin:/usr/bin' + }; + + const result = await execAsync(cliCommand, { env }); + console.log(`PDF conversion stdout: ${result.stdout}`); + if (result.stderr) { + console.warn(`PDF conversion stderr: ${result.stderr}`); + } + } catch (cliError) { + console.error(`PDF conversion error: ${cliError.message}`); + return { + imagePath: '', + originalDimensions: { width: 0, height: 0 }, + imageDimensions: { width: 0, height: 0 }, + success: false, + error: `PDF CLI conversion failed: ${cliError.message}` + }; + } + + // Check if the expected output file exists + try { + await fs.access(expectedOutputPath); + } catch (error) { + return { + imagePath: '', + originalDimensions: { width: 0, height: 0 }, + imageDimensions: { width: 0, height: 0 }, + success: false, + error: `Generated image file not found: ${expectedOutputPath}` + }; + } + + // Rename to our desired format if needed + const finalOutputFileName = `${pdfBaseName}_preview.${opts.format}`; + const finalOutputPath = path.join(outputDir, finalOutputFileName); + + let buffer: Buffer; + if (opts.format === 'jpeg') { + // Convert PNG to JPEG if needed + try { + const sharp = require('sharp'); + const inputBuffer = await fs.readFile(expectedOutputPath); + buffer = await sharp(inputBuffer) + .jpeg({ quality: opts.quality }) + .toBuffer(); + await fs.writeFile(finalOutputPath, buffer); + // Clean up the original PNG + await fs.unlink(expectedOutputPath); + } catch (sharpError) { + console.warn('Sharp not available for JPEG conversion, keeping PNG format'); + // Just rename the file + await fs.rename(expectedOutputPath, finalOutputPath); + buffer = await fs.readFile(finalOutputPath); + } + } else { + // Keep as PNG, just rename + await fs.rename(expectedOutputPath, finalOutputPath); + buffer = await fs.readFile(finalOutputPath); + } + + // Get image dimensions + let imageDimensions = { width: opts.maxWidth, height: opts.maxHeight }; + try { + const sharp = require('sharp'); + const metadata = await sharp(buffer).metadata(); + imageDimensions = { + width: metadata.width || opts.maxWidth, + height: metadata.height || opts.maxHeight + }; + } catch (sharpError) { + // Fallback to estimated dimensions if sharp is not available + console.warn('Sharp not available for image metadata, using estimated dimensions'); + } + + return { + imagePath: finalOutputPath, + originalDimensions: imageDimensions, // Estimate based on converted image + imageDimensions, + success: true + }; + + } catch (error) { + return { + imagePath: '', + originalDimensions: { width: 0, height: 0 }, + imageDimensions: { width: 0, height: 0 }, + success: false, + error: `PDF conversion failed: ${error.message}` + }; + } + } + + /** + * Check if a file is a valid PDF + */ + public async isValidPdf(filePath: string): Promise { + try { + const buffer = await fs.readFile(filePath); + + // Check PDF signature + const signature = buffer.subarray(0, 4).toString(); + return signature === '%PDF'; + } catch (error) { + return false; + } + } + + /** + * Get PDF metadata (page count, dimensions, etc.) + */ + public async getPdfInfo(filePath: string): Promise<{ + pageCount: number; + dimensions: { width: number; height: number }; + success: boolean; + error?: string; + }> { + try { + // pdf-to-img doesn't provide metadata directly + // We'll use a basic approach with the PDF signature check + const isValid = await this.isValidPdf(filePath); + if (!isValid) { + return { + pageCount: 0, + dimensions: { width: 0, height: 0 }, + success: false, + error: 'Invalid PDF file' + }; + } + + // For now, return basic info since pdf-to-img focuses on conversion + // In a real implementation, you might want to use pdf-parse or similar for metadata + return { + pageCount: 1, // We only handle first page anyway + dimensions: { width: 612, height: 792 }, // Standard letter size estimate + success: true + }; + } catch (error) { + return { + pageCount: 0, + dimensions: { width: 0, height: 0 }, + success: false, + error: error.message + }; + } + } +} \ No newline at end of file diff --git a/src/template-manager.ts b/src/template-manager.ts index f325bdc..a8e50e2 100644 --- a/src/template-manager.ts +++ b/src/template-manager.ts @@ -2,244 +2,103 @@ import { App, normalizePath, TFile, TFolder, Notice } from 'obsidian'; import { Template, TemplateVariable, TemplateMetadata, TemplateValidationResult, SubstitutionContext } from './types'; import { TemplateSubstitution } from './template-substitution'; import { TemplateValidator } from './template-validator'; +import * as path from 'path'; /** * Manages Typst templates, including built-in and custom user templates */ export class TemplateManager { private app: App; - private builtInTemplates: Map = new Map(); + private pluginDir: string; + private builtInTemplateNames: string[] = ['default.typ', 'article.typ', 'report.typ', 'single-page.typ']; private customTemplates: Map = new Map(); private customTemplateDirectory: string = 'Typst Templates'; - constructor(app: App, customTemplateDirectory?: string) { + constructor(app: App, pluginDir: string, customTemplateDirectory?: string) { this.app = app; + this.pluginDir = pluginDir; if (customTemplateDirectory) { this.customTemplateDirectory = customTemplateDirectory; } - this.initializeBuiltInTemplates(); } /** - * Initialize built-in Typst templates with modern 0.11+ syntax + * Get the absolute path to a built-in template file */ - private initializeBuiltInTemplates(): void { - // Default template - basic document - this.builtInTemplates.set('default.typ', `#set page( - paper: "a4", - margin: (x: 2.5cm, y: 2cm) -) -#set text( - font: "Liberation Serif", - size: 12pt, - lang: "en" -) -#set par(justify: true, leading: 0.65em) -#set heading(numbering: "1.") + private getBuiltInTemplatePath(templateName: string): string { + return path.join(this.pluginDir, 'templates', templateName); + } -#if "$title$" != "" [ - #align(center, text(18pt, weight: "bold")[$title$]) - #v(1em) -] + /** + * Check if a file exists using Node.js fs (for built-in templates) + */ + private async fileExists(filePath: string): Promise { + try { + const fs = require('fs').promises; + await fs.access(filePath); + return true; + } catch { + return false; + } + } -#if "$author$" != "" [ - #align(center, text(14pt)[$author$]) - #v(0.5em) -] + /** + * Read a file using Node.js fs (for built-in templates) + */ + private async readFile(filePath: string): Promise { + const fs = require('fs').promises; + return await fs.readFile(filePath, 'utf8'); + } -#if "$date$" != "" [ - #align(center, text(12pt)[$date$]) - #v(2em) -] - -$body$`); - - // Article template - academic paper style - this.builtInTemplates.set('article.typ', `#set page( - paper: "a4", - margin: (x: 2.5cm, y: 2cm), - numbering: "1" -) -#set text( - font: "Liberation Serif", - size: 11pt, - lang: "en" -) -#set par(justify: true, leading: 0.65em, first-line-indent: 1.2em) -#set heading(numbering: "1.") - -#show heading.where(level: 1): it => block( - width: 100%, - below: 1.5em, - above: 2em, -)[ - #set align(center) - #set text(16pt, weight: "bold") - #it.body -] - -#show heading.where(level: 2): it => block( - width: 100%, - below: 1em, - above: 1.5em, -)[ - #set text(13pt, weight: "bold") - #it -] - -#if "$title$" != "" [ - #align(center, text(20pt, weight: "bold")[$title$]) - #v(1em) -] - -#if "$author$" != "" [ - #align(center, text(14pt)[$author$]) - #v(0.5em) -] - -#if "$date$" != "" [ - #align(center, text(12pt)[$date$]) - #v(2em) -] - -$body$`); - - // Report template - formal report style - this.builtInTemplates.set('report.typ', `#set page( - paper: "a4", - margin: (x: 2.5cm, y: 2.5cm), - numbering: "1", - header: context { - if counter(page).get().first() > 1 [ - #align(right)[$title$] - #line(length: 100%) - ] - } -) -#set text( - font: "Liberation Serif", - size: 12pt, - lang: "en" -) -#set par(justify: true, leading: 0.65em) -#set heading(numbering: "1.") - -#show heading.where(level: 1): it => pagebreak(weak: true) + block( - width: 100%, - below: 2em, - above: 0pt, -)[ - #set align(center) - #set text(18pt, weight: "bold") - #counter(heading).display() - #h(0.5em) - #it.body -] - -#show heading.where(level: 2): it => block( - width: 100%, - below: 1em, - above: 1.5em, -)[ - #set text(14pt, weight: "bold") - #it -] - -// Title page -#page()[ - #align(center + horizon)[ - #if "$title$" != "" [ - #text(24pt, weight: "bold")[$title$] - #v(2em) - ] - - #if "$author$" != "" [ - #text(16pt)[$author$] - #v(1em) - ] - - #if "$date$" != "" [ - #text(14pt)[$date$] - ] - ] -] - -$body$`); - - // Single-page template - auto-adjusting height - this.builtInTemplates.set('single-page.typ', `#set page( - paper: "a4", - margin: (x: 2.5cm, y: 2cm), - height: auto -) -#set text( - font: "Liberation Serif", - size: 12pt, - lang: "en" -) -#set par(justify: true, leading: 0.65em) -#set heading(numbering: "1.") - -#show heading.where(level: 1): it => block( - width: 100%, - below: 1.5em, - above: 1.5em, -)[ - #set text(16pt, weight: "bold") - #it -] - -#show heading.where(level: 2): it => block( - width: 100%, - below: 1em, - above: 1em, -)[ - #set text(14pt, weight: "bold") - #it -] - -#if "$title$" != "" [ - #align(center, text(18pt, weight: "bold")[$title$]) - #v(1em) -] - -#if "$author$" != "" [ - #align(center, text(14pt)[$author$]) - #v(0.5em) -] - -#if "$date$" != "" [ - #align(center, text(12pt)[$date$]) - #v(2em) -] - -$body$`); + /** + * Initialize built-in Typst templates (now reads from disk) + */ + private async initializeBuiltInTemplates(): Promise { + // Built-in templates are now stored as files in templates/ directory + // This method verifies they exist and are accessible } /** * Get available template names */ - getAvailableTemplates(): string[] { - const builtIn = Array.from(this.builtInTemplates.keys()); + async getAvailableTemplates(): Promise { + const builtIn: string[] = []; + + console.log('TemplateManager: Getting available templates...'); + console.log('Plugin dir:', this.pluginDir); + + // Check which built-in templates exist + for (const templateName of this.builtInTemplateNames) { + const templatePath = this.getBuiltInTemplatePath(templateName); + console.log(`Checking template: ${templateName} at path: ${templatePath}`); + const exists = await this.fileExists(templatePath); + console.log(`Template ${templateName} exists: ${exists}`); + if (exists) { + builtIn.push(templateName); + } + } + const custom = Array.from(this.customTemplates.keys()).map(name => `${name}.typ`); + console.log('Built-in templates found:', builtIn); + console.log('Custom templates found:', custom); return [...builtIn, ...custom]; } /** - * Get template content by name + * Get template file path by name (for use with Pandoc) */ - getTemplate(templateName: string): string | null { + getTemplatePath(templateName: string): string | null { // Check built-in templates first - if (this.builtInTemplates.has(templateName)) { - return this.builtInTemplates.get(templateName) || null; + if (this.builtInTemplateNames.includes(templateName)) { + // Return relative path for Typst templates (not absolute) + // This is because Pandoc + Typst expects relative paths + return `templates/${templateName}`; } // Check custom templates const customKey = templateName.replace('.typ', ''); if (this.customTemplates.has(customKey)) { const template = this.customTemplates.get(customKey); - // For custom templates, we'll need to load the file content - // This will be implemented in the next subtask return template?.filePath || null; } @@ -249,26 +108,39 @@ $body$`); /** * Check if a template exists */ - hasTemplate(templateName: string): boolean { - return this.builtInTemplates.has(templateName) || - this.customTemplates.has(templateName.replace('.typ', '')); + async hasTemplate(templateName: string): Promise { + // Check built-in templates + if (this.builtInTemplateNames.includes(templateName)) { + const templatePath = this.getBuiltInTemplatePath(templateName); + return await this.fileExists(templatePath); + } + + // Check custom templates + return this.customTemplates.has(templateName.replace('.typ', '')); } /** * Get template metadata */ - getTemplateInfo(templateName: string): Partial