in scripts/linkchecker.py [0:0]
def check_anchor(target_page, anchor):
"""Check if an anchor is defined in the target page
:param target_page: The target page to check
:param anchor: Anchor string to find in the target page
"""
if target_page not in ANCHORS:
try:
with open(target_page, "r") as f:
data = f.readlines()
except Exception as ex:
print("[Error] failed in reading markdown file: " + str(ex))
return
content = "\n".join(strip_comments(data))
anchor_pattern1 = r"<a name=\"(.*?)\""
regex1 = re.compile(anchor_pattern1)
anchor_pattern2 = r"{#(.*?)}"
regex2 = re.compile(anchor_pattern2)
ANCHORS[target_page] = regex1.findall(content) + regex2.findall(content)
return anchor in ANCHORS[target_page]