diff --git a/lib/govuk_tech_docs/tech_docs_html_renderer.rb b/lib/govuk_tech_docs/tech_docs_html_renderer.rb index 86416a14..cda21691 100644 --- a/lib/govuk_tech_docs/tech_docs_html_renderer.rb +++ b/lib/govuk_tech_docs/tech_docs_html_renderer.rb @@ -83,13 +83,25 @@ def block_code(text, lang) # to include Middleman::Syntax::RedcarpetCodeRenderer. This defines its own # version of `block_code(text, lang)` which we can call with `super`. - highlighted_html = super - highlighted_html.sub("
#{text}
"
+ fragment = Nokogiri::HTML::DocumentFragment.parse("")
+ pre = Nokogiri::XML::Node.new "pre", fragment
+ pre["tabindex"] = "0"
+ code = Nokogiri::XML::Node.new "code", fragment
+ code["class"] = lang
+ code.content = text
+ pre.add_child code
+ pre.to_html
end
end
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 05efa2f2..85b3dc5d 100644
--- a/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb
+++ b/spec/govuk_tech_docs/tech_docs_html_renderer_spec.rb
@@ -77,7 +77,7 @@ def hello_world
describe "#render a code block" do
it "sets tab index to 0" do
- expect(output).to include('') + expect(output).to include('') end it "renders the code with syntax highlighting" do