MCPcopy Create free account
hub / github.com/DevCloudNinjas/DevOps-Projects / replace_link

Function replace_link

tools/build_starlight_content.py:489–502  ·  view source on GitHub ↗
(match: re.Match[str])

Source from the content-addressed store, hash-verified

487 return f"![{alt}]({GITHUB_RAW}/{raw_path}{title})"
488
489 def replace_link(match: re.Match[str]) -> str:
490 label, raw_target = match.group(1), match.group(2)
491 target, title = split_markdown_destination(raw_target)
492 if is_external_or_anchor(target):
493 if is_same_repo_source_url(target, project_dir):
494 return f"[{label}](#source-files-on-github)"
495 if target.startswith(("http://", "https://")):
496 return external_link(label, target)
497 return match.group(0)
498 source_path, fragment = repo_source_path(project_dir, target)
499 if source_path.lower() in {f"{project_dir}/readme.md", "readme.md", ""}:
500 anchor = f"#{fragment}" if fragment else "#_top"
501 return f"[{label}]({anchor})"
502 return f"[{label}](#source-files-on-github)"
503
504 text = re.sub(r"!\[([^\]]*)\]\(([^)]+)\)", replace_image, text)
505 text = re.sub(r"(?<!!)\[([^\]]+)\]\(([^)]+)\)", replace_link, text)

Callers

nothing calls this directly

Calls 5

is_external_or_anchorFunction · 0.85
is_same_repo_source_urlFunction · 0.85
external_linkFunction · 0.85
repo_source_pathFunction · 0.85

Tested by

no test coverage detected