Support `start-after` option for `.. include::` directive
frankharkins opened this issue · comments
Problem Description
I want to include my README in the index of my API docs, but this results in a duplicate top-level heading as the README has its own title. It's quite a specific use case but probably one that's likely to recur.
Proposal
Implement the start-line
option for the include
directive. Then the following code would resolve the problem.
.. include:: ../README.md
:start-line: 1
Alternatives
Users can use CSS to hide the README heading by its id
, but the navbar still includes the extra heading.
Additional context
I'm happy to make/review the PR if you think this is a good idea. For completeness, I can include the other start-*
and end-*
options but I think the other options are out of scope.
Happy to take a look at a PR! :)
I don't think we have anything else yet that parses directive options, but if we tackle this it probably makes most sense to extract it into a generic helper like so:
def _rst_extract_option(contents: str, option: str) -> tuple[str, str | None]
"""
Extract the specified directive option from contents.
Return updated contents with the option removed and the value of the option if present.
"""
I haven't looked too closely though, feel free to suggest something smarter. :)