Skip to content

Commit

Permalink
fix: simplify wikilink replacement in "lazy mode"
Browse files Browse the repository at this point in the history
  • Loading branch information
Chivier authored and JichouP committed Aug 6, 2023
1 parent 69cbf3c commit 9f23fdd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@ export class PreviewView extends ItemView implements PreviewViewState {

// Function to replace Wikilinks with the desired format
replaceImageWikilinks(markdown: string): string {
const wikilinkRegex = /!\[\[([^\]]+)\]\]/g;
const lines = markdown.split("\n");
const replacedLines = lines.map((line) => {
const replacedLine = line.replace(wikilinkRegex, (match, name) => {
// Modify the format of the Wikilink as needed
const url = this.app.vault.adapter.getResourcePath(name);
return `![${name}](${url})`;
});
return replacedLine;
const wikilinkRegex = /!\[\[(.+?)\]\]/g;
const replacedMarkdown = markdown.replace(wikilinkRegex, (_, name) => {
// Get url for image
const url = this.app.vault.adapter.getResourcePath(name);
return `![${name}](${url})`;
});
return replacedLines.join("\n");
return replacedMarkdown;
}


Expand Down

0 comments on commit 9f23fdd

Please sign in to comment.