INNER CODE UNIT · Python
check_markdown_links
zhinkgit/embeddedskills · .github/maintenance/repo_checks.py:113
def check_markdown_links(root: Path) -> list[str]:
errors: list[str] = []
for path in matching_files(root, "*.md"):
text = path.read_text(encoding="utf-8")
for match in LINK_PATTERN.finditer(text):
target = local_link_target(match.group(1))
if target is None:
continue
resolved = (path.parent / target).resolve()
try:
resolved.relative_to(root.resolve())
except ValueError:
errors.append(
f"{path.relative_to(root)}: local link escapes repository: {target}"
)
continue
if not resolved.exists():
line = text.count("\n", 0, match.start()) + 1