mdsplit: the works inside one file, and the books inside scripture

This commit is contained in:
funkpower
2026-09-19 14:58:54 -04:00
parent fb63b3f9ac
commit ea0a3694b1
41 changed files with 2974 additions and 1 deletions
+49
View File
@@ -0,0 +1,49 @@
"""Split collections the way the Python pipeline splits them.
Reads a markdown document on stdin and writes what the anthology splitter
makes of it.
CATENA_PARITY_PYTHONPATH=/path/to/book-pipeline/src \
python3 oracle/mdsplit.py < case.md
"""
import json
import os
import sys
for path in os.environ.get("CATENA_PARITY_PYTHONPATH", "").split(os.pathsep):
if path:
sys.path.insert(0, path)
from book_pipeline import anthology # noqa: E402
def main() -> int:
markdown = sys.stdin.buffer.read().decode("utf-8")
try:
sections = anthology.detect_sections(markdown)
record = {
"split": True,
"looks_like_bible": anthology._looks_like_bible(markdown),
"sections": [
{
"idx": s.idx,
"title": s.title,
"slug": anthology._slugify(s.title),
"text": s.text,
}
for s in sections
],
}
except anthology.SplitError:
record = {
"split": False,
"looks_like_bible": anthology._looks_like_bible(markdown),
"sections": [],
}
sys.stdout.write(json.dumps(record, ensure_ascii=False, sort_keys=True) + "\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())