1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00
Radicale/documentation-generator/filter.py

35 lines
839 B
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Filter program for transforming the Pandoc AST
"""
import json
import sys
2021-12-14 00:23:13 +01:00
TITLE = "Documentation"
def main():
data = json.load(sys.stdin)
2021-12-14 22:27:10 +01:00
level1_headings = [
(i, content) for i, (level, _, content)
in ((i, b["c"]) for i, b in enumerate(data["blocks"])
if b["t"] == "Header")
if level == 1]
if (len(level1_headings) != 1
or level1_headings[0][1] != [{"t": "Str", "c": TITLE}]):
print(("ERROR: Document must contain single level 1 heading "
"with content %r") % TITLE, file=sys.stderr)
2021-12-14 00:23:13 +01:00
exit(1)
2021-12-14 22:27:10 +01:00
for i, _ in reversed(level1_headings):
2021-12-14 00:23:13 +01:00
del data["blocks"][i]
2021-12-14 22:27:10 +01:00
data["meta"]["title"] = {"t": "MetaInlines", "c": level1_headings[0][1]}
json.dump(data, sys.stdout)
if __name__ == "__main__":
main()