Skip to content

Commit 7fbea37

Browse files
author
Ozan Tellioglu
committed
Review Corrections 3
1 parent fcfe169 commit 7fbea37

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/converter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import LinkConverterPlugin from 'main';
2-
import { App, TFile, normalizePath, Notice } from 'obsidian';
2+
import { App, TFile, Notice } from 'obsidian';
33

44
/* -------------------- LINK DETECTOR -------------------- */
55

@@ -109,11 +109,10 @@ const getAllLinkMatchesInFile = async (mdFile: TFile, plugin: LinkConverterPlugi
109109

110110
// --> Converts single file to provided final format and save back in the file
111111
export const convertLinksAndSaveInSingleFile = async (mdFile: TFile, plugin: LinkConverterPlugin, finalFormat: 'markdown' | 'wiki') => {
112-
let normalizedPath = normalizePath(mdFile.path);
113112
let fileText = await plugin.app.vault.read(mdFile);
114113
let newFileText =
115114
finalFormat === 'markdown' ? await convertWikiLinksToMarkdown(fileText, mdFile, plugin) : await convertMarkdownLinksToWikiLinks(fileText, mdFile, plugin);
116-
await plugin.app.vault.adapter.write(normalizedPath, newFileText);
115+
await plugin.app.vault.modify(mdFile, newFileText);
117116
};
118117

119118
// --> Command Function: Converts All Links and Saves in Current Active File
@@ -199,8 +198,7 @@ const convertMarkdownLinksToWikiLinks = async (md: string, sourceFile: TFile, pl
199198
/* -------------------- LINKS TO RELATIVE/ABSOLUTE/SHORTEST -------------------- */
200199

201200
export const convertLinksInFileToPreferredFormat = async (mdFile: TFile, plugin: LinkConverterPlugin, finalFormat: FinalFormat) => {
202-
let normalizedPath = normalizePath(mdFile.path);
203-
let fileText = await plugin.app.vault.adapter.read(normalizedPath);
201+
let fileText = await plugin.app.vault.read(mdFile);
204202
let linkMatches: LinkMatch[] = await getAllLinkMatchesInFile(mdFile, plugin);
205203
for (let linkMatch of linkMatches) {
206204
let fileLink = decodeURI(linkMatch.linkText);
@@ -210,7 +208,7 @@ export const convertLinksInFileToPreferredFormat = async (mdFile: TFile, plugin:
210208
fileText = fileText.replace(linkMatch.match, createLink(linkMatch.type, fileLink, linkMatch.altOrBlockRef, mdFile, plugin));
211209
}
212210
}
213-
await plugin.app.vault.adapter.write(normalizedPath, fileText);
211+
await plugin.app.vault.modify(mdFile, fileText);
214212
};
215213

216214
const getFileLinkInFormat = (file: TFile, sourceFile: TFile, plugin: LinkConverterPlugin, finalFormat: FinalFormat): string => {

0 commit comments

Comments
 (0)