Skip to content

Duplicate ids #23

@vnq

Description

@vnq

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 3

Which 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:

  1. 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_0 it could become #Head1_1 over time.
  2. Use the parent in the id i.e. #Head2_Head1 this 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions