Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions obsidian_interactive_graph/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ def collect_pages(self, nav: MkDocsNav, config: MkDocsConfig):
}

def parse_markdown(self, markdown: str, page: MkDocsPage):
# wikilinks: [[Link#Anchor|Custom Text]], just the link is needed
WIKI_PATTERN = re.compile(r"(?<!\!)\[\[(?P<wikilink>[^\|^\]^\#]{1,})(?:.*?)\]\]")
# wikilinks: just the link is needed
# Obsidian: [[Link#Anchor|Custom Text]]
# Markdown: [Custom Text](Link)
WIKI_PATTERN = re.compile(r"(?<!\!)\[\[(?P<obsidianlink>[^\|^\]^\#]+)(?:.*?)\]\]|(?<!\!)\[[^\]]+\]\((?P<markdownlink>[^\)^\#]+)(?:#[^\)]*)?\)")

for match in re.finditer(WIKI_PATTERN, markdown):
wikilink = match.group('wikilink')
wikilink = match.group('obsidianlink') or match.group('markdownlink')

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

# find something that matches: shortest path depth
abslen = None
for k,_ in self.nodes.items():
for k, _ in self.nodes.items():
for _ in re.finditer(re.compile(r"(.*" + wikilink + r")"), k):
curlen = k.count('/')
if abslen == None or curlen < abslen:
if abslen is None or curlen < abslen:
target_page_path = k
abslen = curlen

Expand Down