Now also Markdown links get recognized.
This commit is contained in:
parent
a785270fda
commit
b3a40035cd
1 changed files with 34 additions and 2 deletions
36
omg.py
36
omg.py
|
@ -132,6 +132,32 @@ class OMG:
|
||||||
if not tag == "":
|
if not tag == "":
|
||||||
file_metadata["tags"].append(tag.lower())
|
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 ====
|
# ==== wikilinks ====
|
||||||
if not "[[" in line or not "]]" in line:
|
if not "[[" in line or not "]]" in line:
|
||||||
continue
|
continue
|
||||||
|
@ -146,8 +172,14 @@ class OMG:
|
||||||
|
|
||||||
tokens = link.split("|") # ["relPath, "link"]
|
tokens = link.split("|") # ["relPath, "link"]
|
||||||
|
|
||||||
link = tokens[0].split("/")[-1]
|
link = tokens[0].split("/")[-1].strip().replace("\\", "")
|
||||||
relpath = os.path.relpath(os.path.join(path, "../" + tokens[0]), self.path) + ".md"
|
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}
|
link_data = {"link": link, "relativePath": relpath}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue