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.
This commit is contained in:
7 files changed
+27
-29
No files matched your search
@@ -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);
|
||||
|
||||
@@ -88,7 +88,7 @@ export class EmbedProcessor {
|
||||
* Returns the local path if successful, null if failed
|
||||
*/
|
||||
private async downloadRemoteImage(imageUrl: string, tempDir: string): Promise<string | null> {
|
||||
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}`);
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+11
-15
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user