Now also Markdown links get recognized.

This commit is contained in:
The Wobbler 2025-04-09 18:10:29 +02:00
parent a785270fda
commit b3a40035cd

36
omg.py
View file

@ -132,6 +132,32 @@ class OMG:
if not tag == "":
file_metadata["tags"].append(tag.lower())
# ==== markdown links ====
if "[" in line and "]" in line and "(" in line and ")" in line:
for link in line.split("["):
if not "]" in link:
continue
tokens = link.split("]")
display_text = tokens[0]
url = tokens[1]
if url == "" or not url[0] == "(" or not url[-1] == ")": # link has no proper url enclosure
continue
url = url[1:-1]
url = url.split()[0]
link = url.split("/")[-1].strip()
relpath = os.path.relpath(os.path.join(path, "../" + url), self.path).strip()
if not relpath.endswith(".md"):
relpath += ".md"
link = {"link": link, "relativePath": relpath, "displayText": display_text}
file_metadata["links"].append(link)
# ==== wikilinks ====
if not "[[" in line or not "]]" in line:
continue
@ -146,8 +172,14 @@ class OMG:
tokens = link.split("|") # ["relPath, "link"]
link = tokens[0].split("/")[-1]
relpath = os.path.relpath(os.path.join(path, "../" + tokens[0]), self.path) + ".md"
link = tokens[0].split("/")[-1].strip().replace("\\", "")
relpath = os.path.relpath(
os.path.join(path, "../" + tokens[0]),
self.path
).strip().replace("\\", "")
if not relpath.endswith(".md"):
relpath += ".md"
link_data = {"link": link, "relativePath": relpath}