in update-imported-docs/update-imported-docs.py [0:0]
def process_links(content, remote_prefix, sub_path):
"""Process markdown links found in the docs."""
def analyze(match_obj):
ankor = match_obj.group('ankor')
target = match_obj.group('target')
if not (target.startswith("https://") or
target.startswith("mailto:") or
target.startswith("#")):
if target.startswith("/"):
target_list = remote_prefix, target[1:]
target = "/".join(target_list)
else:
target_list = remote_prefix, sub_path, target
target = "/".join(target_list)
return "[%s](%s)" % (ankor, target)
# Links are in the form '[text](url)'
link_regex = re.compile(r"\[(?P<ankor>.*)\]\((?P<target>.*)\)")
content = re.sub(link_regex, analyze, content)
h1_regex = re.compile("^(# .*)?\n")
content = re.sub(h1_regex, "", content)
return content