-
Notifications
You must be signed in to change notification settings - Fork 128
Markdown template skips h2 level when no section exists #663
Copy link
Copy link
Closed
Description
MyST doesn’t like that and throws a warning. I’d like to stay warning-free without spuriously ignoring warnings.
I filed #664, but a better solution for this is (and would have been for #648) to add a “initial section depth” config option for markdown instead of allowing users to customize the title section depth while not adapting the other sections.
We can kinda hack this in with the current solution as well:
if m := re.fullmatch(r"([^\n]*\n)*(?P<hashes>#+)\s.*", title_format, re.MULTILINE):
initial_depth = len(m["hashes"])
else:
initial_depth = 1
sec_depth = initial_depth + 1
cat_depths = defaultdict(lambda: sec_depth + 1)
cat_depths[""] = sec_depth
depth = dict(title=initial_depth, section=sec_depth, category=cat_depths)and the template could read for e.g. the section header:
{{ "#" * depth["section"] }} {{section}}and for the category header:
{{ "#" * depth["category"][section] }} {{ definitions[category]['name'] }}alternative implementation
or less complex code
[…]
cat_depth = sec_depth + 1
depth = dict(title=initial_depth, section=sec_depth, category=cat_depth)and more complex template
{{ "#" * depth["category" if section else "section"] }} {{ definitions[category]['name'] }}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels