executablebooks / MyST-Parser

An extended commonmark compliant parser, with bridges to docutils/sphinx
https://myst-parser.readthedocs.io
MIT License
714 stars 191 forks source link

third occurence of heading with the same title cannot be referenced, `[myst.xref_missing]` #878

Open ClementPinard opened 5 months ago

ClementPinard commented 5 months ago

What version of myst-parser are you using?

2.0.0

What version dependencies are you using?

sphinx : 6.2.1 docutils 0.19

What operating system are you using?

Ubuntu 22.04

Describe the Bug

In the docs (especially here https://myst-parser.readthedocs.io/en/latest/syntax/cross-referencing.html#implicit-targets) it says that the slugs for headings matches the github slugger. As such, when headings have the same name, the second occurence gets a suffix of -1, and the third should get -2 and so on.

It looks like this works for myst parser but only for two headings. As soon as there are 3 headings with the same name (can happen with subsections that follow a pattern between sections), any cross ref fails

Capture d’écran du 2024-02-26 23-40-38

See how I get the warning 'myst' reference target not found: 'heading-2' [myst.xref_missing] even though the slug does exist in the html.

Expected Behavior

[Link to the heading 3](#heading-2) should link to the third occurence of the heading titled "heading" and not issue a warning

To Reproduce

This bug is very to reproduce since it happens on the live preview https://myst-parser.readthedocs.io/en/latest/live-preview.html#

# Heading

Hallo world!

[Link to the heading](#heading)

[Link to the heading 2](#heading-1)

[Link to the heading 3](#heading-2)

# Heading

The second heading

# Heading

the third heading

I kept the default configuration, i.e.

myst_enable_extensions:
- colon_fence
- deflist
- dollarmath
myst_heading_anchors: 2
myst_highlight_code_blocks: true
welcome[bot] commented 5 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada: