From 7d805eda45bbed7b1452957163a35b5bacf51ef0 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 5 Nov 2025 17:25:01 +0100 Subject: [PATCH] Standardizes terminology and error handling Corrects capitalization inconsistencies in UI and documentation, improving clarity and professionalism. Enhances error handling in the image download function by properly rejecting promises on errors, thus increasing reliability and maintainability. Relates to obsidian-bot-review branch tasks. --- src/plugin/CommandRegistry.ts | 2 +- src/plugin/EmbedProcessor.ts | 10 ++++++---- src/plugin/EventHandlers.ts | 6 +++--- src/plugin/ExportOrchestrator.ts | 6 +++--- src/plugin/SettingsTab.ts | 26 +++++++++++-------------- src/ui/modal/ModalRenderer.ts | 2 +- src/ui/modal/sections/GeneralSection.ts | 4 ++-- 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/plugin/CommandRegistry.ts b/src/plugin/CommandRegistry.ts index 3c8e73b..714b3cf 100644 --- a/src/plugin/CommandRegistry.ts +++ b/src/plugin/CommandRegistry.ts @@ -38,7 +38,7 @@ export class CommandRegistry { // Check dependencies command this.plugin.addCommand({ id: 'check-dependencies', - name: 'Check Pandoc and Typst dependencies', + name: 'Check pandoc and typst dependencies', callback: () => { this.plugin.showDependencyStatus().catch(error => { console.error('Failed to show dependency status:', error); diff --git a/src/plugin/EmbedProcessor.ts b/src/plugin/EmbedProcessor.ts index ea180b3..59c3f9d 100644 --- a/src/plugin/EmbedProcessor.ts +++ b/src/plugin/EmbedProcessor.ts @@ -88,7 +88,7 @@ export class EmbedProcessor { * Returns the local path if successful, null if failed */ private async downloadRemoteImage(imageUrl: string, tempDir: string): Promise { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { try { // Parse URL to get filename const urlObj = new URL(imageUrl); @@ -124,7 +124,7 @@ export class EmbedProcessor { const absoluteRedirectUrl = new URL(redirectUrl, imageUrl).href; console.debug(`Export:Following redirect to: ${absoluteRedirectUrl}`); // Recursively follow redirect with resolved absolute URL - this.downloadRemoteImage(absoluteRedirectUrl, tempDir).then(resolve); + this.downloadRemoteImage(absoluteRedirectUrl, tempDir).then(resolve).catch(reject); return; } } @@ -143,7 +143,8 @@ export class EmbedProcessor { chunks.push(chunk); }); - response.on('end', async () => { + response.on('end', () => { + void (async () => { try { // Check if file already exists to avoid overwriting const exists = await this.pathUtils.fileExists(outputPath); @@ -165,7 +166,8 @@ export class EmbedProcessor { console.error(`Export: Error writing image file: ${err.message}`); resolve(null); } - }); + })(); + }); response.on('error', (err) => { console.error(`Export: Error receiving image data: ${err.message}`); diff --git a/src/plugin/EventHandlers.ts b/src/plugin/EventHandlers.ts index 0333a8c..49229e0 100644 --- a/src/plugin/EventHandlers.ts +++ b/src/plugin/EventHandlers.ts @@ -20,7 +20,7 @@ export class EventHandlers { if (file.extension === 'md') { menu.addItem((item) => { item - .setTitle('Export to PDF (Typst)') + .setTitle('Export to PDF') .setIcon('file-output') .onClick(() => { this.plugin.exportFile(file).catch(error => { @@ -37,7 +37,7 @@ export class EventHandlers { this.plugin.app.workspace.on('editor-menu', (menu: Menu, editor: Editor, view: MarkdownView) => { menu.addItem((item) => { item - .setTitle('Export to PDF (Typst)') + .setTitle('Export to PDF') .setIcon('file-output') .onClick(() => { this.plugin.exportCurrentNote(view).catch(error => { @@ -57,7 +57,7 @@ export class EventHandlers { if (markdownFiles.length > 0) { menu.addItem((item) => { item - .setTitle(`Export to PDF (Typst)`) + .setTitle(`Export to PDF`) .setIcon('file-output') .onClick(() => { this.plugin.exportFiles(markdownFiles).catch(error => { diff --git a/src/plugin/ExportOrchestrator.ts b/src/plugin/ExportOrchestrator.ts index 39a48bf..a5e6e53 100644 --- a/src/plugin/ExportOrchestrator.ts +++ b/src/plugin/ExportOrchestrator.ts @@ -162,9 +162,9 @@ export class ExportOrchestrator { cls: 'mod-warning' }); cancelButton.addEventListener('click', () => this.cancelExport()); - progressNotice.setMessage('Preprocessing markdown content...'); + progressNotice.setMessage('Preprocessing Markdown content...'); - // Preprocess markdown + // Preprocess Markdown const preprocessor = new MarkdownPreprocessor({ vaultPath: vaultPath, options: { @@ -322,7 +322,7 @@ export class ExportOrchestrator { const markdownFiles = folder.children.filter((file) => this.plugin.isMarkdownFile(file)); if (markdownFiles.length === 0) { - new Notice('No markdown files found in this folder'); + new Notice('No Markdown files found in this folder'); return; } diff --git a/src/plugin/SettingsTab.ts b/src/plugin/SettingsTab.ts index 10607ef..622990d 100644 --- a/src/plugin/SettingsTab.ts +++ b/src/plugin/SettingsTab.ts @@ -28,10 +28,6 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { const { containerEl } = this; containerEl.empty(); - new Setting(containerEl) - .setName('Typst PDF Export Settings') - .setHeading(); - // Executable paths section this.createExecutablePathsSection(containerEl); @@ -66,9 +62,9 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Pandoc path') - .setDesc('Path to pandoc executable (leave empty to use system PATH)') + .setDesc('Path to pandoc executable (leave empty to use system path)') .addText(text => text - .setPlaceholder('pandoc') + .setPlaceholder('Pandoc') .setValue(this.plugin.settings.pandocPath) .onChange(async (value) => { if (!SecurityUtils.validateExecutablePath(value)) { @@ -81,9 +77,9 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Typst path') - .setDesc('Path to typst executable (leave empty to use system PATH)') + .setDesc('Path to typst executable (leave empty to use system path)') .addText(text => text - .setPlaceholder('typst') + .setPlaceholder('Typst') .setValue(this.plugin.settings.typstPath) .onChange(async (value) => { if (!SecurityUtils.validateExecutablePath(value)) { @@ -95,10 +91,10 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { })); new Setting(containerEl) - .setName('ImageMagick path') - .setDesc('Path to ImageMagick executable (leave empty to use system PATH)') + .setName('Imagemagick path') + .setDesc('Path to imagemagick executable (leave empty to use system path)') .addText(text => text - .setPlaceholder('magick') + .setPlaceholder('Magick') .setValue(this.plugin.settings.executablePaths.imagemagickPath) .onChange(async (value) => { if (!SecurityUtils.validateExecutablePath(value)) { @@ -141,7 +137,7 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Default template') - .setDesc('Default Typst template for exports') + .setDesc('Default typst template for exports') .addDropdown(async (dropdown) => { try { const templates = await this.plugin.templateManager.getAvailableTemplates(); @@ -163,7 +159,7 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { } catch (error) { console.error('Failed to load templates:', error); // Fallback to text input - dropdown.addOption('default.typ', 'default.typ'); + dropdown.addOption('default.typ', 'Default.typ'); dropdown.setValue(this.plugin.settings.exportDefaults.template); } }); @@ -182,10 +178,10 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Output folder') - .setDesc('Default folder for exported PDFs (relative to vault root)') + .setDesc('Folder for exported pdfs (relative to vault root)') .addText(text => { text - .setPlaceholder('exports') + .setPlaceholder('Exports') .setValue(this.plugin.settings.outputFolder) .onChange(async (value) => { const normalizedValue = normalizePath(value); diff --git a/src/ui/modal/ModalRenderer.ts b/src/ui/modal/ModalRenderer.ts index dd07b7d..7e6bc9f 100644 --- a/src/ui/modal/ModalRenderer.ts +++ b/src/ui/modal/ModalRenderer.ts @@ -154,7 +154,7 @@ export class ModalRenderer { text: 'Export', cls: 'mod-cta' }); - this.submitButton.addEventListener('click', () => this.callbacks.onSubmit()); + this.submitButton.addEventListener('click', () => void this.callbacks.onSubmit()); } /** diff --git a/src/ui/modal/sections/GeneralSection.ts b/src/ui/modal/sections/GeneralSection.ts index d1802e2..c3539a4 100644 --- a/src/ui/modal/sections/GeneralSection.ts +++ b/src/ui/modal/sections/GeneralSection.ts @@ -74,10 +74,10 @@ export class GeneralSection implements ModalSection { new Setting(this.container) .setName('Output folder') - .setDesc('Folder where PDFs will be saved (relative to vault root)') + .setDesc('Location for exported PDF files (relative to vault root)') .addText(text => { const input = text - .setPlaceholder('exports') + .setPlaceholder('PDF exports') .setValue(state.settings.outputFolder || 'exports') .onChange(value => { const normalizedValue = normalizePath(value);