question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

include directive: start from alternative heading level

See original GitHub issue

Thanks 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:open
  • Created 3 years ago
  • Reactions:6
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisjsewellcommented, Feb 15, 2021

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 level

1reaction
chrisjsewellcommented, Jan 20, 2021

No 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

# title
## sub-title
# title
### sub-title
## title
### sub-title

all are parsed to sphinx AST:

<section>
  <section>

which will then be always rendered as

# title
## sub-title

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

reStructuredText Directives - Docutils
Directives begin with an explicit markup start (two periods and a space), followed by the directive type and two colons (collectively, the "directive...
Read more >
Python Sphinx include directive: ignore the header from ...
Looking at neighbour raw directive tried and now it works! This code includes the part.rst from the 5th line (after my heading) .....
Read more >
Sphinx and RST syntax guide (0.9.3) - Thomas-Cokelaer.info
Sphinx and the RST syntax provides directives to include formatted text. As an example, let us consider the code-block syntax.
Read more >
reStructuredText Primer — Sphinx v1.0.8 documentation
Basically, a directive consists of a name, arguments, options and content. (Keep this terminology in mind, it is used in the next chapter...
Read more >
reStructuredText Markup - Python Developer's Guide
Normally, there are no heading levels assigned to certain characters as the structure ... This directive marks the beginning of the description of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found