- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation. - Adjusted assertions to use multi-line formatting for better readability. - Added new test cases for theme settings API to ensure proper functionality. - Ensured consistent use of line breaks and spacing across test files for uniformity.
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""Simple Markdown link checker for local docs/ files.
|
|
|
|
Checks only local file links (relative paths) and reports missing targets.
|
|
|
|
Run from the repository root using the project's Python environment.
|
|
"""
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
DOCS = ROOT / "docs"
|
|
|
|
MD_LINK_RE = re.compile(r"\[([^\]]+)\]\(([^)]+)\)")
|
|
|
|
errors = []
|
|
|
|
for md in DOCS.rglob("*.md"):
|
|
text = md.read_text(encoding="utf-8")
|
|
for m in MD_LINK_RE.finditer(text):
|
|
label, target = m.groups()
|
|
# skip URLs
|
|
if (
|
|
target.startswith("http://")
|
|
or target.startswith("https://")
|
|
or target.startswith("#")
|
|
):
|
|
continue
|
|
# strip anchors
|
|
target_path = target.split("#")[0]
|
|
# if link is to a directory index, allow
|
|
candidate = (md.parent / target_path).resolve()
|
|
if candidate.exists():
|
|
continue
|
|
# check common implicit index: target/ -> target/README.md or target/index.md
|
|
candidate_dir = md.parent / target_path
|
|
if candidate_dir.is_dir():
|
|
if (candidate_dir / "README.md").exists() or (
|
|
candidate_dir / "index.md"
|
|
).exists():
|
|
continue
|
|
errors.append((str(md.relative_to(ROOT)), target, label))
|
|
|
|
if errors:
|
|
print("Broken local links found:")
|
|
for src, tgt, label in errors:
|
|
print(f"- {src} -> {tgt} ({label})")
|
|
exit(2)
|
|
|
|
print("No broken local links detected.")
|