This commit is contained in:
Unrud 2022-04-24 19:14:26 +02:00
parent ee786fd6bd
commit b496be0f5d
2 changed files with 11 additions and 9 deletions

View file

@ -13,19 +13,21 @@ TITLE = "Documentation"
def main():
data = json.load(sys.stdin)
level1_headings = [
# Check and remove level 1 header
level1_header = [
(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)
exit(1)
for i, _ in reversed(level1_headings):
if (len(level1_header) != 1
or level1_header[0][1] != [{"t": "Str", "c": TITLE}]):
print("ERROR: Document must contain single level 1 heading %r" % TITLE,
file=sys.stderr)
sys.exit(1)
for i, _ in reversed(level1_header):
del data["blocks"][i]
data["meta"]["title"] = {"t": "MetaInlines", "c": level1_headings[0][1]}
# Use level 1 heading as title
data["meta"]["title"] = {"t": "MetaInlines", "c": level1_header[0][1]}
json.dump(data, sys.stdout)

View file

@ -61,7 +61,7 @@ def main():
checks_failed = True
if checks_failed:
exit(1)
sys.exit(1)
sys.stdout.buffer.write(soup.encode(formatter="html5") + b"\n")