mirror of
https://github.com/Kozea/Radicale.git
synced 2025-04-06 22:57:36 +03:00
Refactor
This commit is contained in:
parent
ee786fd6bd
commit
b496be0f5d
2 changed files with 11 additions and 9 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue