search: fix anchor ids for duplicate headers #1749
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #720, #1579
Currently, if one page contains two sections with the same header, the generated anchor IDs will be uniquely enumerated:
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 functionid_from_content
is publicly exported and so cannot be deleted - it has been marked as deprecated from the next patch version0.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!