Skip to content

Commit

Permalink
Patch GovukTechDocs::TechDocsHTMLRenderer
Browse files Browse the repository at this point in the history
Add a new `preprocess` hook to the Redcarpet renderer to reset the ID generator.
This ensures headings that may appear on multiple pages are not treated as duplicate
when rendering one of these pages.

See: alphagov/tech-docs-gem#310
  • Loading branch information
romaricpascal committed Nov 17, 2022
1 parent 69d439a commit 78f40d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require "govuk_tech_docs"
require "lib/sassdocs_helpers"

# Patch the GovukTechDocs cleanly
# https://www.justinweiss.com/articles/3-ways-to-monkey-patch-without-making-a-mess/
require "lib/ext/govuk_tech_docs/tech_docs_html_renderer/reset_unique_identifier_generator_preprocess"
GovukTechDocs::TechDocsHTMLRenderer.include Ext::GovukTechDocs::TechDocsHTMLRenderer::ResetUniqueIndentifierGeneratorPreprocess

config[:build_dir] = "deploy/public"

GovukTechDocs.configure(self)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Ext
module GovukTechDocs
module TechDocsHTMLRenderer
module ResetUniqueIndentifierGeneratorPreprocess
##
# Fix for the unique ID generation not being reset for each document
# leading to IDs being considered duplicates when on different pages
# while they shouldn't be
#
# @see https://github.com/alphagov/tech-docs-gem/issues/310

def preprocess(document)
##
# Resets the UniqueIdentifierGenerator before the document gets processed
#
# @see https://github.com/vmg/redcarpet#prepost-process

::GovukTechDocs::UniqueIdentifierGenerator.instance.reset

document
end
end
end
end
end
10 changes: 5 additions & 5 deletions source/javascript-api-reference/index.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ GOVUKFrontend.initAll({
})
```

## Accordion component
## Accordion

### i18n

Expand Down Expand Up @@ -117,7 +117,7 @@ Default:
"Show this section"
```

## Button component
## Button

### preventDoubleClick

Expand All @@ -131,7 +131,7 @@ Default:
false
```

## CharacterCount component
## CharacterCount

### maxlength

Expand Down Expand Up @@ -287,7 +287,7 @@ Default:
}
```

## ErrorSummary component
## ErrorSummary

### disableAutoFocus

Expand All @@ -301,7 +301,7 @@ Default
false
```

## NotificationBanner component
## NotificationBanner

### `disableAutoFocus`

Expand Down

0 comments on commit 78f40d4

Please sign in to comment.