Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support start-after option for .. include:: directive #682

Closed
frankharkins opened this issue Apr 14, 2024 · 1 comment · Fixed by #684
Closed

Support start-after option for .. include:: directive #682

frankharkins opened this issue Apr 14, 2024 · 1 comment · Fixed by #684

Comments

@frankharkins
Copy link
Contributor

frankharkins commented Apr 14, 2024

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.

Screenshot

Screenshot from 2024-04-14 18-17-50

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.

@mhils
Copy link
Member

mhils commented Apr 14, 2024

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants