diff --git a/src/constants.ts b/src/constants.ts index 1568c46..b15fd7d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,5 @@ export const MM_VIEW_TYPE = 'mindmap'; export const MD_VIEW_TYPE = 'markdown'; -export const INTERNAL_LINK_REGEX = /\[\[(.*)\]\]/g; \ No newline at end of file + +// https://regex101.com/r/gw85cc/2 +export const INTERNAL_LINK_REGEX = /\[\[(?.*)\]\]|(?.*)<\/a>/gim; \ No newline at end of file diff --git a/src/obsidian-markmap-plugin.ts b/src/obsidian-markmap-plugin.ts index 844540b..f2452f4 100644 --- a/src/obsidian-markmap-plugin.ts +++ b/src/obsidian-markmap-plugin.ts @@ -18,12 +18,20 @@ export default class ObsidianMarkmap { private replaceInternalLinks(node: INode){ const matches = this.parseValue(node.v); - matches.forEach(match => { - const linkText = match[1]; - const url = `obsidian://vault/${this.vaultName}/${encodeURI(getLinkpath(linkText))}`; + console.log(node.v); + for (let i = 0; i < matches.length; i++) { + const match = matches[i]; + const isWikiLink = match.groups['wikitext']; + const linkText = isWikiLink ? match.groups['wikitext'] : match.groups['mdtext']; + const linkPath = isWikiLink ? linkText : match.groups['mdpath']; + if(linkPath.startsWith('http')){ + continue; + } + const url = `obsidian://open?vault=${this.vaultName}&file=${isWikiLink ? encodeURI(getLinkpath(linkPath)) : linkPath}`; const link = `${linkText}`; - node.v = node.v.replace(/\[\[.*\]\]/, link); - }); + console.log(match); + node.v = node.v.replace(match[0], link); + } } private parseValue(v: string) {