in scripts/linkchecker.py [0:0]
def validate_links(page):
"""Find and validate links on a content page.
The checking records are consolidated into the global variable RESULT.
"""
try:
with open(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))
# Single results: searches for pattern: []()
link_pattern = r"\[([`/\w\s\n]*)\]\(([^\)]*)\)"
regex = re.compile(link_pattern)
matches = regex.findall(content)
records = []
for m in matches:
r = check_target(page, m[0], m[1])
if r:
records.append(r)
# searches for pattern: {{< api-reference page="" anchor=""
apiref_pattern = r"{{ *< *api-reference page=\"([^\"]*?)\" *anchor=\"(.*?)\""
regex = re.compile(apiref_pattern)
matches = regex.findall(content)
for m in matches:
r = check_apiref_target(m[0], m[1])
if r:
records.append(r)
# searches for pattern: {{< api-reference page=""
apiref_pattern = r"{{ *< *api-reference page=\"([^\"]*?)\""
regex = re.compile(apiref_pattern)
matches = regex.findall(content)
for m in matches:
r = check_apiref_target(m, None)
if r:
records.append(r)
if len(records):
RESULT[page] = records