35 lines
861 B
Python
35 lines
861 B
Python
#!/usr/bin/env python3
|
|
"""Draft artifact: md_inspect.py — lightweight Markdown structure inspector."""
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def inspect(path: str) -> dict:
|
|
text = Path(path).read_text(encoding="utf-8")
|
|
lines = text.splitlines()
|
|
headings = [ln for ln in lines if re.match(r"^#{1,6}\s", ln)]
|
|
words = len(text.split())
|
|
links = re.findall(r"\[[^\]]+\]\([^\)]+\)", text)
|
|
return {
|
|
"file": path,
|
|
"lines": len(lines),
|
|
"headings": len(headings),
|
|
"words": words,
|
|
"links": len(links),
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) < 2:
|
|
print("usage: md_inspect.py <file.md>", file=sys.stderr)
|
|
return 2
|
|
data = inspect(sys.argv[1])
|
|
for k, v in data.items():
|
|
print(f"{k}={v}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|