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

Same header names generate identical HTML anchors #530

Closed
JCGoran opened this issue Sep 24, 2023 · 1 comment · Fixed by #540
Closed

Same header names generate identical HTML anchors #530

JCGoran opened this issue Sep 24, 2023 · 1 comment · Fixed by #540

Comments

@JCGoran
Copy link

JCGoran commented Sep 24, 2023

Describe the bug
This is a report from downstream, see mitmproxy/pdoc#534 and mitmproxy/pdoc#497 for more details (was told to report it here).

To Reproduce
Long story short, when using markdown2 as part of pdoc to generate documentation of a Python project, and one has two identically-named headers in different docstrings (but the same module/file), they will generate an identical anchor.

Expected behavior
Different headers with same names should have different anchors so they can be properly referenced.

Additional context
I haven't found anything in the Markdown spec that mentions what should be done in case of identical headers (or how the anchors should be generated in the first place), so technically this is not a bug, but an issue with the spec being undefined (or implementation-defined?). Nevertheless, it would be nice if there was an option in this library to disambiguate headers with the same name via some option.

@Crozzers
Copy link
Contributor

The header-ids extra does generate unique anchors for identical headers:

# abc
# abc
# abc
<h1 id="abc">abc</h1>

<h1 id="abc-2">abc</h1>

<h1 id="abc-3">abc</h1>

I think the problem is that the way pdoc converts docstrings is by passing each one as a markdown snippet, rather than a single document. Every time pdoc calls Markdown.convert, the counter that keeps track of header IDs is reset as part of the _setup_extras function

The solution here would be to either persist the header count across resets or provide some way of preventing the reset between conversions.

nicholasserra added a commit that referenced this issue Dec 3, 2023
Add mechanism to prevent header ID counter resetting (issue #530)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants