mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Use level 1 heading as title
This commit is contained in:
parent
208c869b6b
commit
ad604dcab7
2 changed files with 21 additions and 7 deletions
|
@ -8,7 +8,7 @@ import json
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from run import SHIFT_HEADING
|
TITLE = "Documentation"
|
||||||
|
|
||||||
|
|
||||||
def text_content(content):
|
def text_content(content):
|
||||||
|
@ -33,13 +33,23 @@ def convert_framgent(*titles):
|
||||||
def main():
|
def main():
|
||||||
data = json.load(sys.stdin)
|
data = json.load(sys.stdin)
|
||||||
|
|
||||||
|
delete_block_indices = []
|
||||||
|
level1_heading = None
|
||||||
# Use hierachical link fragments (e.g. #heading/subheading)
|
# Use hierachical link fragments (e.g. #heading/subheading)
|
||||||
headings = []
|
headings = []
|
||||||
for block in data["blocks"]:
|
for i, block in enumerate(data["blocks"]):
|
||||||
if block["t"] != "Header":
|
if block["t"] != "Header":
|
||||||
continue
|
continue
|
||||||
level, (attr_id, attr_class, attr_name), content = block["c"]
|
level, (attr_id, attr_class, attr_name), content = block["c"]
|
||||||
shifted_level = level - SHIFT_HEADING
|
if level == 1:
|
||||||
|
if level1_heading is not None:
|
||||||
|
print("ERROR: Mulitple level 1 headings found",
|
||||||
|
file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
delete_block_indices.append(i)
|
||||||
|
level1_heading = content
|
||||||
|
continue
|
||||||
|
shifted_level = level - 1 # Ignore level 1 heading
|
||||||
title = text_content(content)
|
title = text_content(content)
|
||||||
headings = headings[:shifted_level - 1]
|
headings = headings[:shifted_level - 1]
|
||||||
while len(headings) < shifted_level - 1:
|
while len(headings) < shifted_level - 1:
|
||||||
|
@ -47,6 +57,12 @@ def main():
|
||||||
headings.append(title)
|
headings.append(title)
|
||||||
full_attr_id = convert_framgent(*headings)
|
full_attr_id = convert_framgent(*headings)
|
||||||
block["c"] = [level, [full_attr_id, attr_class, attr_name], content]
|
block["c"] = [level, [full_attr_id, attr_class, attr_name], content]
|
||||||
|
if level1_heading != [{'t': 'Str', 'c': TITLE}]:
|
||||||
|
print("ERROR: Level 1 heading must be %r" % TITLE, file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
data["meta"]["title"] = {"t": "MetaInlines", "c": level1_heading}
|
||||||
|
for i in reversed(delete_block_indices):
|
||||||
|
del data["blocks"][i]
|
||||||
|
|
||||||
json.dump(data, sys.stdout)
|
json.dump(data, sys.stdout)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@ GIT_CONFIG = {"protocol.version": "2",
|
||||||
COMMIT_MESSAGE = "Generate documentation"
|
COMMIT_MESSAGE = "Generate documentation"
|
||||||
DOCUMENTATION_SRC = "DOCUMENTATION.md"
|
DOCUMENTATION_SRC = "DOCUMENTATION.md"
|
||||||
REDIRECT_CONFIG_PATH = "redirect.json"
|
REDIRECT_CONFIG_PATH = "redirect.json"
|
||||||
SHIFT_HEADING = 1
|
TOC_DEPTH = 4
|
||||||
TOC_DEPTH = 3
|
|
||||||
TOOLS_PATH = os.path.dirname(__file__)
|
TOOLS_PATH = os.path.dirname(__file__)
|
||||||
REDIRECT_TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template-redirect.html")
|
REDIRECT_TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template-redirect.html")
|
||||||
TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html")
|
TEMPLATE_PATH = os.path.join(TOOLS_PATH, "template.html")
|
||||||
|
@ -64,8 +63,7 @@ def convert_doc(src_path, to_path, branch, branches):
|
||||||
"--template=%s" % os.path.basename(TEMPLATE_PATH),
|
"--template=%s" % os.path.basename(TEMPLATE_PATH),
|
||||||
"--metadata-file=%s" % os.path.abspath(metadata_file.name),
|
"--metadata-file=%s" % os.path.abspath(metadata_file.name),
|
||||||
"--section-divs",
|
"--section-divs",
|
||||||
"--shift-heading-level-by=%d" % SHIFT_HEADING,
|
"--toc-depth=%d" % TOC_DEPTH,
|
||||||
"--toc-depth=%d" % (TOC_DEPTH+SHIFT_HEADING),
|
|
||||||
"--filter=%s" % os.path.abspath(FILTER_EXE)],
|
"--filter=%s" % os.path.abspath(FILTER_EXE)],
|
||||||
cwd=os.path.dirname(TEMPLATE_PATH),
|
cwd=os.path.dirname(TEMPLATE_PATH),
|
||||||
stdout=subprocess.PIPE, check=True).stdout
|
stdout=subprocess.PIPE, check=True).stdout
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue