diff --git a/lib/govuk_tech_docs/tech_docs_html_renderer.rb b/lib/govuk_tech_docs/tech_docs_html_renderer.rb index 241d8dbf..35fa653a 100644 --- a/lib/govuk_tech_docs/tech_docs_html_renderer.rb +++ b/lib/govuk_tech_docs/tech_docs_html_renderer.rb @@ -11,6 +11,12 @@ def initialize(options = {}) super end + def preprocess(document) + UniqueIdentifierGenerator.instance.reset + + document + end + def paragraph(text) @app.api("

#{text.strip}

\n") end diff --git a/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb b/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb index deadf61a..5ed75d39 100644 --- a/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb +++ b/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb @@ -109,7 +109,7 @@ def hello_world expect(output).to include('

A heading

') expect(output).to include('

A subheading

') end - + it "Ensures IDs are unique among headings in the page" do output = processor.render <<~MARKDOWN # A heading @@ -130,5 +130,19 @@ def hello_world # Finally the last occurence will get a prefix, but no number as it's in a different section expect(output).to include('

A shared heading

') end + + it "Does not consider unique IDs across multiple renders" do + processor.render <<~MARKDOWN + # A heading + ## A subheading + MARKDOWN + + second_output = processor.render <<~MARKDOWN + # A heading + ## A subheading + MARKDOWN + + expect(second_output).to include('

A subheading

') + end end end