quill: add md_inspect.py draft artifact
This commit is contained in:
1 parent
0d0b8b360d
commit
3cab270aa4
2 files changed
+42
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#!/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())
|
||||
@@ -0,0 +1,8 @@
|
||||
# Heading One
|
||||
Some text here.
|
||||
|
||||
## Heading Two
|
||||
More text with a [link](https://example.com) and [another](https://example.org).
|
||||
|
||||
### Heading Three
|
||||
Even more text.
|
||||
Reference in new issue
Block a user