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

Customize level of headings that are wrapped in anchor links? #725

Open
adigitoleo opened this issue Aug 9, 2024 · 6 comments
Open

Customize level of headings that are wrapped in anchor links? #725

adigitoleo opened this issue Aug 9, 2024 · 6 comments

Comments

@adigitoleo
Copy link

Problem Description

Currently, pdoc renders markdown headings within docstrings (e.g. ### Heading) into HTML heading elements (e.g. h3). However, it is not possible to link to specific headings within a docstring because they are not wrapped in an <a>anchor</a> element.

My intended use case is to be able to reference specific headings in a module-level docstring (or in __init__.py), in the same way that I am able to reference class and function definitions in the API docs.

Proposal

Wrap rendered headings within docstrings in HTML anchor elements.

Alternatives

I guess the alternative is to manually maintain a TOC at the top of the docstring to at least give a quick visual overview.

@adigitoleo
Copy link
Author

Oops, I think I'm being silly. There do seem to be anchor links in the published version of our docs, but not when I preview the live version on localhost. Is that intended? I'll check on another browser to be sure...

@adigitoleo
Copy link
Author

OH ok, it only adds anchor links for h1 and h2. That seems sensible. Am I missing that in the pdoc docs somewhere? Or should it be added?

Feel free to close.

@adigitoleo adigitoleo changed the title Anchor links for headings in markdown docstrings? Customize level of headings that are wrapped in anchor links? Aug 9, 2024
@mhils
Copy link
Member

mhils commented Aug 9, 2024

I don't think it's in the docs, but happy to merge a PR that adds it to the "header-ids" bullet in https://pdoc.dev/docs/pdoc.html#markdown-support! :)

@adigitoleo
Copy link
Author

happy to merge a PR

Can do, I just want to clarify that markdown2 doesn't support customizing which heading level is the cutoff. That seems to be the case, am I right?

@mhils
Copy link
Member

mhils commented Aug 9, 2024 via email

@adigitoleo
Copy link
Author

Hmm, can't see anything. I think the part of markdown2 responsible for this is the "header ids" extra, which only has a brief wiki entry here. Nothing about h2 being the maximum. I tried searching in the 4k line markdown2 implementation for "header-ids" but couldn't work out where this limitation is coming from... In any case maybe the correct place to document this is in the header-ids wiki entry (that pdoc already links to) but I'd have to ask over there to find out what is going on.

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

No branches or pull requests

2 participants