include directive: start from alternative heading level
See original GitHub issueThanks for the great project. I perfectly fits the use case I have, with one minor issue.
TL;DR: Is it possible to fix or ignore non-consecutive header levels?
For a group of related projects, I want the contributors to write all the documentation in a single README.md.
From the README and the docstrings, I generate the online docs with Sphinx and MyST.
I want the sections of the README to end up in separate documents of my generated docs.
The docs/
directory is populated with generic stub files that are generated by a cookiecutter.
The README always has the same sections (second level):
# project-name
## Usage
## Installation
## Changelog
### 0.1.0 (2020-10-01)
## Contributing
...
From this, I generate separate pages (e.g. changelog.md):
# Changelog
```{include} ..\README.md
:start-after: "## Changelog"
:end-before: "## Contributing"
My index.md:
# project-name
```{toctree}
installation.md
usage.md
api.md
changelog.md
contribution.md
```
What was a level 2 heading now should be a level 1 heading in the split documents.
When building the docs, MyST emits the warning Non-consecutive header level increase
because of this. The warning is correct and intended, see #71, but is there any way around this? I want to treat Sphinx warnings as errors, because it has proven very helpful in the past.
Possible solutions:
- Is it possible to disable the specific warning? Sphinx offers suppress_warnings, but I couldn’t figure out the type for this warning.
- Is there a possibility to modify header levels of the included documents, or to set the initial level from 0 to 1?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:7 (4 by maintainers)
Top GitHub Comments
With https://github.com/executablebooks/MyST-Parser/pull/313, this warning can now be suppressed.
I will leave this issue open though, as for
include
it would probably be better to have an extra option to “add/minus x” to the initial heading levelNo this warning arises directly from MyST-Parser: https://github.com/executablebooks/MyST-Parser/blob/4e02629f5fb575fdd733ca43891bebb2e312ad00/myst_parser/docutils_renderer.py#L258-L266
correctly, because for example
all are parsed to sphinx AST:
which will then be always rendered as
so it is not possible to conserve the original levels, if they are not consecutive and starting from 1
include
is a special case though, since you are inserting into an existing document, it does make sense to potentially start at a level greater than 1