Skip to content

Commit 70e0ed5

Browse files
committed
added initial support for plain markdown links
1 parent 5dae201 commit 70e0ed5

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

obsidian_interactive_graph/plugin.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ def collect_pages(self, nav: MkDocsNav, config: MkDocsConfig):
5454
}
5555

5656
def parse_markdown(self, markdown: str, page: MkDocsPage):
57-
# wikilinks: [[Link#Anchor|Custom Text]], just the link is needed
58-
WIKI_PATTERN = re.compile(r"(?<!\!)\[\[(?P<wikilink>[^\|^\]^\#]{1,})(?:.*?)\]\]")
57+
# wikilinks: just the link is needed
58+
# Obsidian: [[Link#Anchor|Custom Text]]
59+
# Markdown: [Custom Text](Link)
60+
WIKI_PATTERN = re.compile(r"(?<!\!)\[\[(?P<obsidianlink>[^\|^\]^\#]+)(?:.*?)\]\]|(?<!\!)\[[^\]]+\]\((?P<markdownlink>[^\)^\#]+)(?:#[^\)]*)?\)")
61+
5962
for match in re.finditer(WIKI_PATTERN, markdown):
60-
wikilink = match.group('wikilink')
63+
wikilink = match.group('obsidianlink') or match.group('markdownlink')
6164

6265
# get the nodes key
6366
page_path = self.get_page_path(page)
@@ -75,10 +78,10 @@ def parse_markdown(self, markdown: str, page: MkDocsPage):
7578

7679
# find something that matches: shortest path depth
7780
abslen = None
78-
for k,_ in self.nodes.items():
81+
for k, _ in self.nodes.items():
7982
for _ in re.finditer(re.compile(r"(.*" + wikilink + r")"), k):
8083
curlen = k.count('/')
81-
if abslen == None or curlen < abslen:
84+
if abslen is None or curlen < abslen:
8285
target_page_path = k
8386
abslen = curlen
8487

0 commit comments

Comments
 (0)