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

Duplicate ids #23

Open
vnq opened this issue Jan 28, 2022 · 1 comment
Open

Duplicate ids #23

vnq opened this issue Jan 28, 2022 · 1 comment

Comments

@vnq
Copy link
Contributor

vnq commented Jan 28, 2022

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.

@KEINOS
Copy link
Owner

KEINOS commented Jan 29, 2022

TL; DR

+1

A practical solution would be to provide "options" such as "append_numbering" and/or "append_level".

TS; DR

Yea, you got the point. If the header is the same, the bookmark link will be the same. It's been a problem since issue #3. So I think it's a kinda dup-issue, though.

However, I agree with you. Not all documents have a unique title. And, as you say, the titles of two different levels can be the same.

There are two reasons why this issue #3 has not been closed.

  1. Like the conventions of the HTML id attribute, links on a page (bookmark-link) must be unique.
  2. The Markdown Lint that I use fails if there are multiple headings in the document that have the same text.

So, the current "best" solution was to "write a document with a unique heading title" ... 😭

But, as you suggested, adding something to the bookmark anchor might be the solution.

Yes, the order may change as the document is updated. Though, this also applies to the header title itself. As long as the link is generated dynamically, there is no way to specify the link permanently.

Thus, a practical solution would be to provide options such as "append_numbering" and/or "append_level" and let the user decide.

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

No branches or pull requests

2 participants