Fix ID shared by different pages being considered duplicates #311
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.
Fix for #310 where pages sharing the same headings referenced in the navigation would end up with these headings treated as duplicates when their ID get generated for the navigation links. This would make the link point to the wrong ID and not fullfill their role of sending the user straight to the right section.
What’s changed
The commits should paint a step by step decription of the changes. As a broad summary, this PR changes when the
UniqueIdentifierGenerator
gets reset. It makes it happen before each Markdown render, rather than on Middleman'sbefore
hook (whose timing is still very unclear to me, but led to the original situation).I did also try to tie the resets to a Rack middleware, to ensure they happen for every request made to Middleman (which surprisingly didn't match the
before
hook), but the issue remained.The PR also cleans things up now the generator's lifecycle is bound to that of Redcarpet's renderer:
Each of these two bits is done in their own separate commit so could be easily dropped if we fear this may break things for people using the gem.
I've also added a few tests around the
TechDocsHTMLRenderer
to validate the heading generation.Identifying a user need
This issue was discovered while adding JavaScript API documentation alongside the Sass one in the govuk-frontend docs. It may hit any documentation whose pages share the same heading structure (either written manually or automated).
Closes #310