Skip to content

Commit

Permalink
using normalizePath is recommended and now implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ullmannJan committed Feb 7, 2024
1 parent b619862 commit f23971a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/ConverterModal.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<void>((resolve, reject) => {
this.convertTiffToPng(tiffFilePath)
Expand Down
7 changes: 4 additions & 3 deletions src/DeleteModal.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<void>((resolve, reject) => {
this.deleteTiffPngFileInEditor(tiffPngFilePath)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit f23971a

Please sign in to comment.