-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
If no self-defined ids are used, there is a chance for duplicate ids. See the following example:
# Head1
Sample text of head 1.
## Head1-1
Sample text of head 1-1.
# Head2
Sample text of head 2.
## 見出し2-1
Sample text of head2-1.
## Head1
Duplicate subheading.
# Head3 {#self-defined-head3}
Sample text of head 3Which will translate to:
<ul>
<li><a href="#Head1">Head1</a>
<ul>
<li><a href="#Head1-1">Head1-1</a></li>
</ul></li>
<li><a href="#Head2">Head2</a>
<ul>
<li><a href="#%E8%A6%8B%E5%87%BA%E3%81%972-1">見出し2-1</a></li>
<li><a href="#Head1">Head1</a></li>
</ul></li>
<li><a href="#self-defined-head3">Head3</a></li>
</ul>You'll notice the #Head1 is defined twice and thus will always scroll to the first id, as ids have to be unique.
I thought of two solutions:
- Make sure duplicate ids can never happen. If it already exists append something (count?) so it'll stay unique. The downside would however be that the ids will change over time i.e. you bookmarked
#Head1_0it could become#Head1_1over time. - Use the parent in the id i.e.
#Head2_Head1this at least prevents our described use case, but it'll still allow for the following which would cause the same problem:
# Head
Paragraph
## Subhead
Paragraph
# Head
Paragraph
## Subhead
Paragraph
So the best solution actually might be combination of both. Of course other solutions are welcome.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels