diff --git a/main.ts b/main.ts index 024dd10..6ea4d4f 100644 --- a/main.ts +++ b/main.ts @@ -121,7 +121,7 @@ export default class TiffViewerPlugin extends Plugin { matches.forEach(match => { const editorContent = editor.getValue(); - const newEditorContent = editorContent.replace(match, match.replace('.png', '')); + const newEditorContent = editorContent.replace(match, match.replace('.png]]', ']]')); editor.setValue(newEditorContent); }); } diff --git a/src/ConverterModal.ts b/src/ConverterModal.ts index af66667..7927554 100644 --- a/src/ConverterModal.ts +++ b/src/ConverterModal.ts @@ -1,4 +1,4 @@ -import { App, Editor } from "obsidian"; +import { App, Editor, normalizePath } from "obsidian"; import { SuperModal } from "./SuperModal"; const UTIF = require('utif'); const PNG = require('pngjs').PNG; @@ -39,7 +39,7 @@ export class ConverterModal extends SuperModal { console.log('found tiff files', matches); const conversionPromises = matches.map(match => { const tiffFile = match.replace('![[', '').replace(']]', ''); - const tiffFilePath = tiffFile.replace(/\\/g, '/'); + const tiffFilePath = normalizePath(tiffFile); return new Promise((resolve, reject) => { this.convertTiffToPng(tiffFilePath) diff --git a/src/DeleteModal.ts b/src/DeleteModal.ts index 6ba68e0..07eb844 100644 --- a/src/DeleteModal.ts +++ b/src/DeleteModal.ts @@ -1,6 +1,6 @@ -import { App, Editor } from "obsidian"; +import { App, Editor, normalizePath } from "obsidian"; import { SuperModal } from "./SuperModal"; - +import { normalize } from "path"; export class DeleteModal extends SuperModal { progressbar: HTMLProgressElement; @@ -35,7 +35,7 @@ export class DeleteModal extends SuperModal { console.log('found .tiff.png files', matches); const conversionPromises = matches.map(match => { const tiffPngFile = match.replace('![[', '').replace(']]', ''); - const tiffPngFilePath = tiffPngFile.replace(/\\/g, '/'); + const tiffPngFilePath = normalizePath(tiffPngFile); return new Promise((resolve, reject) => { this.deleteTiffPngFileInEditor(tiffPngFilePath) @@ -77,6 +77,7 @@ export class DeleteModal extends SuperModal { // rename file in editor const editorContent = this.editor.getValue(); + // remove .png from file name const newEditorContent = editorContent.replace(filePath, filePath.slice(0, -4)); this.editor.setValue(newEditorContent);