Skip to content

Commit

Permalink
Remove support for block and inline code
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBiddle committed Sep 8, 2023
1 parent df8516f commit 8134e84
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/govuk-forms-markdown/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ def block_quote(quote)
paragraph(quote)
end

def block_code(code, _lang)
add_to_error(:used_block_code)
paragraph(code)
end

def hrule
add_to_error(:used_hrule)
nil
end

def codespan(code)
add_to_error(:used_codespan)
code
end

def emphasis(text)
add_to_error(:used_emphasis)
text
Expand Down
28 changes: 28 additions & 0 deletions spec/govuk-forms-markdown/renderer/block_code_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# rubocop:disable RSpec/FilePath
RSpec.describe GovukFormsMarkdown::Renderer, "#block_code" do
subject(:renderer) { described_class.new }

it "does not format block_code" do
expect(renderer.block_code("strong {\n color: rebeccapurple;\n}", "css").strip).to eq "<p class=\"govuk-body\">strong {\n color: rebeccapurple;\n}</p>"
end

describe "rendering errors" do
it "does log an error for block_code being used" do
renderer.block_code("strong {\n color: rebeccapurple;\n}", "css")
expect(renderer.errors).to eq([:used_block_code])
end

context "when block_code is called multiple times in a single render" do
it "returns the warning exactly once" do
renderer.block_code("strong {\n color: rebeccapurple;\n}", "css")
renderer.block_code("strong {\n color: rebeccapurple;\n}", "css")

expect(renderer.errors.length).to eq 1
expect(renderer.errors).to eq([:used_block_code])
end
end
end
end
# rubocop:enable RSpec/FilePath
28 changes: 28 additions & 0 deletions spec/govuk-forms-markdown/renderer/codespan_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# rubocop:disable RSpec/FilePath
RSpec.describe GovukFormsMarkdown::Renderer, "#codespan " do
subject(:renderer) { described_class.new }

it "does not format codespan" do
expect(renderer.codespan("color: rebeccapurple;")).to eq "color: rebeccapurple;"
end

describe "rendering errors" do
it "does log an error for codespan being used" do
renderer.codespan("color: rebeccapurple;")
expect(renderer.errors).to eq([:used_codespan])
end

context "when codespan is called multiple times in a single render" do
it "returns the warning exactly once" do
renderer.codespan("color: rebeccapurple;")
renderer.codespan("color: rebeccapurple;")

expect(renderer.errors.length).to eq 1
expect(renderer.errors).to eq([:used_codespan])
end
end
end
end
# rubocop:enable RSpec/FilePath

0 comments on commit 8134e84

Please sign in to comment.