mirror of
https://github.com/ethanolivertroy/obsidian-markitdown.git
synced 2026-07-22 05:41:54 +00:00
Remove preview modal — conversions save directly (ENG-643 reverted)
This commit is contained in:
parent
fb07e1c98b
commit
48cf0c1147
2 changed files with 10 additions and 55 deletions
30
main.ts
30
main.ts
|
|
@ -29,7 +29,6 @@ import { FolderConvertModal } from './src/modals/FolderConvertModal';
|
||||||
import { UrlConvertModal } from './src/modals/UrlConvertModal';
|
import { UrlConvertModal } from './src/modals/UrlConvertModal';
|
||||||
import { HistoryModal } from './src/modals/HistoryModal';
|
import { HistoryModal } from './src/modals/HistoryModal';
|
||||||
import { SetupModal } from './src/modals/SetupModal';
|
import { SetupModal } from './src/modals/SetupModal';
|
||||||
import { PreviewModal } from './src/modals/PreviewModal';
|
|
||||||
|
|
||||||
export default class MarkitdownPlugin extends Plugin {
|
export default class MarkitdownPlugin extends Plugin {
|
||||||
settings: MarkitdownSettings = DEFAULT_SETTINGS;
|
settings: MarkitdownSettings = DEFAULT_SETTINGS;
|
||||||
|
|
@ -274,30 +273,11 @@ export default class MarkitdownPlugin extends Plugin {
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
let content: string;
|
const msg = result.imagesExtracted
|
||||||
try {
|
? `Converted successfully (${result.imagesExtracted} images extracted)`
|
||||||
content = await fs.promises.readFile(outputPath, 'utf-8');
|
: 'Converted successfully';
|
||||||
} catch {
|
new Notice(msg);
|
||||||
new Notice('Conversion succeeded but could not read output file');
|
await this.openConvertedFile(outputPath, vaultPath);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new PreviewModal(this.app, {
|
|
||||||
content,
|
|
||||||
outputPath,
|
|
||||||
processingTime: result.processingTime ?? 0,
|
|
||||||
onSave: async () => {
|
|
||||||
const msg = result.imagesExtracted
|
|
||||||
? `Converted successfully (${result.imagesExtracted} images extracted)`
|
|
||||||
: 'Converted successfully';
|
|
||||||
new Notice(msg);
|
|
||||||
await this.openConvertedFile(outputPath, vaultPath);
|
|
||||||
},
|
|
||||||
onCancel: async () => {
|
|
||||||
await fs.promises.unlink(outputPath).catch(() => {});
|
|
||||||
new Notice('Conversion discarded');
|
|
||||||
},
|
|
||||||
}).open();
|
|
||||||
} else {
|
} else {
|
||||||
new Notice(`Conversion failed: ${result.error}`);
|
new Notice(`Conversion failed: ${result.error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import * as fs from 'fs';
|
||||||
import type MarkitdownPlugin from '../../main';
|
import type MarkitdownPlugin from '../../main';
|
||||||
import { FILE_INPUT_ACCEPT } from '../utils/fileTypes';
|
import { FILE_INPUT_ACCEPT } from '../utils/fileTypes';
|
||||||
import { getVaultBasePath, resolveOutputFolder, resolveFilenameTemplate, toVaultRelative } from '../utils/paths';
|
import { getVaultBasePath, resolveOutputFolder, resolveFilenameTemplate, toVaultRelative } from '../utils/paths';
|
||||||
import { PreviewModal } from './PreviewModal';
|
|
||||||
|
|
||||||
export class FileConvertModal extends Modal {
|
export class FileConvertModal extends Modal {
|
||||||
private plugin: MarkitdownPlugin;
|
private plugin: MarkitdownPlugin;
|
||||||
|
|
@ -68,36 +67,12 @@ export class FileConvertModal extends Modal {
|
||||||
const result = await this.plugin.convertExternalFile(tempFilePath, outputPath);
|
const result = await this.plugin.convertExternalFile(tempFilePath, outputPath);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Read the converted output for preview
|
const msg = result.imagesExtracted
|
||||||
let content: string;
|
? `Converted successfully (${result.imagesExtracted} images extracted)`
|
||||||
try {
|
: 'Converted successfully';
|
||||||
content = await fs.promises.readFile(outputPath, 'utf-8');
|
new Notice(msg);
|
||||||
} catch {
|
await this.plugin.openConvertedFile(outputPath, vaultPath);
|
||||||
new Notice('Conversion succeeded but could not read output file');
|
|
||||||
convertButton.disabled = false;
|
|
||||||
convertButton.setText('Convert');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
new PreviewModal(this.app, {
|
|
||||||
content,
|
|
||||||
outputPath,
|
|
||||||
processingTime: result.processingTime ?? 0,
|
|
||||||
onSave: async () => {
|
|
||||||
const msg = result.imagesExtracted
|
|
||||||
? `Converted successfully (${result.imagesExtracted} images extracted)`
|
|
||||||
: 'Converted successfully';
|
|
||||||
new Notice(msg);
|
|
||||||
await this.plugin.openConvertedFile(outputPath, vaultPath);
|
|
||||||
},
|
|
||||||
onCancel: async () => {
|
|
||||||
// Discard the converted output file
|
|
||||||
await fs.promises.unlink(outputPath).catch(() => {});
|
|
||||||
new Notice('Conversion discarded');
|
|
||||||
},
|
|
||||||
}).open();
|
|
||||||
} else {
|
} else {
|
||||||
new Notice(`Conversion failed: ${result.error}`);
|
new Notice(`Conversion failed: ${result.error}`);
|
||||||
convertButton.disabled = false;
|
convertButton.disabled = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue