You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the longest time, nested headers in myst-parser have been a pain, particularly in things like admonitions
In Markdown (and HTML) headings are allowed "anywhere", for example:
```markdown
> # Heading 1
## Heading 2
Paragraph
```
Is rendered as:
```html
<blockquote>
<h1>Heading 1</h1>
</blockquote>
<h2>Heading 2</h2>
<p>Paragraph</p>
```
However, because docutils/sphinx treats headers as nested sections, this becomes problematic
```xml
<blockquote>
<section>
<title>
Heading 1
<section>
<title>
Heading 2
<paragraph>
Paragraph
```
Which sphinx cannot resolve the ToC tree from etc
This PR fixes this, by identifying if a heading is inside another component and instead outputting it as a "non-structural" rubric node
```xml
<blockquote>
<rubric level=1>
Heading 1
<section>
<title>
Heading 2
<paragraph>
Paragraph
```
Natively, docutils/sphinx does not deal with the "level" key in the rubric,
so here we also override the rubric HTML renderer to correctly output a `<h>` element, if "level" is present, to retrieve the desired:
```html
<blockquote>
<h1>Heading 1</h1>
</blockquote>
<h2>Heading 2</h2>
<p>Paragraph</p>
```
There is no longer any warning of nested headers, since this is the intended behaviour
To clarify, the logic is now:
- A section can only be a child of the root document, or another section
- If a header token is encountered, with a child that is not one of these, then it is added as a rubric
- Otherwise a new section is created, and the heading is added as a title, which is a child of the section
0 commit comments