Skip to content

Commit 9f23fdd

Browse files
ChivierJichouP
authored andcommitted
fix: simplify wikilink replacement in "lazy mode"
1 parent 69cbf3c commit 9f23fdd

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/preview.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,13 @@ export class PreviewView extends ItemView implements PreviewViewState {
3737

3838
// Function to replace Wikilinks with the desired format
3939
replaceImageWikilinks(markdown: string): string {
40-
const wikilinkRegex = /!\[\[([^\]]+)\]\]/g;
41-
const lines = markdown.split("\n");
42-
const replacedLines = lines.map((line) => {
43-
const replacedLine = line.replace(wikilinkRegex, (match, name) => {
44-
// Modify the format of the Wikilink as needed
45-
const url = this.app.vault.adapter.getResourcePath(name);
46-
return `![${name}](${url})`;
47-
});
48-
return replacedLine;
40+
const wikilinkRegex = /!\[\[(.+?)\]\]/g;
41+
const replacedMarkdown = markdown.replace(wikilinkRegex, (_, name) => {
42+
// Get url for image
43+
const url = this.app.vault.adapter.getResourcePath(name);
44+
return `![${name}](${url})`;
4945
});
50-
return replacedLines.join("\n");
46+
return replacedMarkdown;
5147
}
5248

5349

0 commit comments

Comments
 (0)