Correct for hash-indexing in auto-relinker
This commit is contained in:
parent
a1290cdb5e
commit
20a1741f4c
1 changed files with 6 additions and 5 deletions
|
|
@ -38,9 +38,7 @@ def create_toctree():
|
||||||
"accept doc-files with the same name, even in different folders.")
|
"accept doc-files with the same name, even in different folders.")
|
||||||
docref_map[fname] = url
|
docref_map[fname] = url
|
||||||
|
|
||||||
ref_regex = re.compile(r"\[(?P<txt>[\w -\[\]]+?)\]\((?P<url>"
|
ref_regex = re.compile(r"\[(?P<txt>[\w -\[\]]+?)\]\((?P<url>.+?)\)", re.I + re.S + re.U)
|
||||||
+ r"|".join(docref_map)
|
|
||||||
+ r")\)", re.I + re.S + re.U)
|
|
||||||
|
|
||||||
def _sub(match):
|
def _sub(match):
|
||||||
grpdict = match.groupdict()
|
grpdict = match.groupdict()
|
||||||
|
|
@ -48,9 +46,12 @@ def create_toctree():
|
||||||
fname, *part = url.rsplit("/", 1)
|
fname, *part = url.rsplit("/", 1)
|
||||||
fname = part[0] if part else fname
|
fname = part[0] if part else fname
|
||||||
fname = fname.rsplit(".", 1)[0]
|
fname = fname.rsplit(".", 1)[0]
|
||||||
urlout = docref_map.get(fname, url)
|
fname, *anchor = url.rsplit("#", 1)
|
||||||
if url != urlout:
|
if fname in docref_map:
|
||||||
|
urlout = docref_map[fname] + ('#' + anchor[0] if anchor else '')
|
||||||
print(f" Remapped link [{txt}]({url}) -> [{txt}]({urlout})")
|
print(f" Remapped link [{txt}]({url}) -> [{txt}]({urlout})")
|
||||||
|
else:
|
||||||
|
urlout = url
|
||||||
return f"[{txt}]({urlout})"
|
return f"[{txt}]({urlout})"
|
||||||
|
|
||||||
# replace / correct links in all files
|
# replace / correct links in all files
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue