From 435f0a5c9bf8d70fba4a27aabbdce154dfaa0bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Niclas=20W=C3=A4chtler?= <54584804+cubexy@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:58:57 +0200 Subject: [PATCH] add custom image embedding and ability to add link to printed pages --- main.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index 64eedcf..4035324 100644 --- a/main.ts +++ b/main.ts @@ -17,11 +17,15 @@ import { FolderSuggest } from "utils/suggest/folderSuggest"; interface PdfPrinterSettings { imageFolder: string; imageQuality: number; + imageEmbedFormat: string; + preservePdfLink: boolean; } const DEFAULT_SETTINGS: PdfPrinterSettings = { imageFolder: "", imageQuality: 0.5, + imageEmbedFormat: "![[${filename}]]", + preservePdfLink: false, }; type PdfDocumentBuffer = { @@ -63,11 +67,20 @@ export default class PdfPrinterPlugin extends Plugin { return; } - editor.replaceSelection( - imagePathList - .map((imagePath) => `![[${imagePath}]]`) - .join("\n") - ); + const imageLinks = imagePathList + .map((imagePath) => + this.settings.imageEmbedFormat.replace( + "${filename}", + imagePath + ) + ) + .join("\n"); + + const replacementText = this.settings.preservePdfLink + ? `[[${pdfFile.path}]]\n${imageLinks}` + : `\n${imageLinks}`; + + editor.replaceSelection(replacementText); new Notice( `Document '${pdfFile.name}' was printed successfully.` @@ -263,5 +276,33 @@ class PdfPrinterSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); + + new Setting(this.containerEl) + .setName("Show link to original PDF above printed images") + .setDesc( + "Keep a link to the original PDF above the printed images as a reference." + ) + .addToggle((cb) => { + cb.setValue(this.plugin.settings.preservePdfLink).onChange( + async (value) => { + this.plugin.settings.preservePdfLink = value; + await this.plugin.saveSettings(); + } + ); + }); + + new Setting(this.containerEl) + .setName("Image embed format") + .setDesc( + "Format for embedding images in the markdown file. Use ${filename} as a placeholder for the image file name." + ) + .addText((cb) => { + cb.setPlaceholder("![[${filename}]]") + .setValue(this.plugin.settings.imageEmbedFormat) + .onChange(async (value) => { + this.plugin.settings.imageEmbedFormat = value; + await this.plugin.saveSettings(); + }); + }); } }