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

search: fix anchor ids for duplicate headers #1749

Merged
merged 1 commit into from
Mar 28, 2022

Conversation

tommilligan
Copy link
Contributor

Closes: #720, #1579

Currently, if one page contains two sections with the same header, the generated anchor IDs will be uniquely enumerated:

<h3 id="my-title">
  <a class="header" href="#my-title">My Title</a>
</h3>
...
<h3 id="my-title-1">
  <a class="header" href="#my-title-1">My Title</a>
</h3>

However, search doesn't match the way it generates ids from header content, and doesn't enumerate them. This leads to all search results for a given section header, linking to the first section header with that content on the page.


This PR factors out unique id generation for headers to a new function, unique_id_from_content. The existing function id_from_content is publicly exported and so cannot be deleted - it has been marked as deprecated from the next patch version 0.4.16.

Matching tests have been added, and I have verified that this works for my specific use case locally.

Let me know if there's anything that needs changing - thanks very much for maintaining this project!

@tommilligan tommilligan changed the title search: match all generated anchor ids search: fix anchor ids for duplicate headers Feb 18, 2022
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

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 this pull request may close these issues.

Search does not handle headers with special formatting.
2 participants