diff --git a/lib/govspeak.rb b/lib/govspeak.rb index 97bc5b03..a9e4b203 100644 --- a/lib/govspeak.rb +++ b/lib/govspeak.rb @@ -136,6 +136,7 @@ def insert_strong_inside_p(body, parser=Govspeak::Document) end extension('button', %r{ + ^ # Match start of line only, allows for indenting code examples {button(.*?)} # match opening bracket and capture attributes \s* # any whitespace between opening bracket and link \[ # match start of link markdown @@ -146,6 +147,7 @@ def insert_strong_inside_p(body, parser=Govspeak::Document) \) # match end of link text markdown \s* # any whitespace between opening bracket and link {\/button} # match ending bracket + $ # Match end of line only, allows for indenting code examples }x) { |attributes, text, href| button_classes = "button" button_classes << " button-start" if attributes =~ /start/ diff --git a/lib/govspeak/html_sanitizer.rb b/lib/govspeak/html_sanitizer.rb index 10fe2a26..c6feaa23 100644 --- a/lib/govspeak/html_sanitizer.rb +++ b/lib/govspeak/html_sanitizer.rb @@ -59,7 +59,7 @@ def sanitize_without_images def button_sanitize_config [ - "data-module='cross-domain-tracking'", + "data-module", "data-tracking-code", "data-tracking-name" ] diff --git a/test/govspeak_button_test.rb b/test/govspeak_button_test.rb index 1980b590..eeca5e24 100644 --- a/test/govspeak_button_test.rb +++ b/test/govspeak_button_test.rb @@ -45,17 +45,6 @@ class GovspeakTest < Minitest::Test assert_html_output '
{button}I shouldn’t render a button{/button}
' end - test_given_govspeak "Text before the button {button}[Start Now](http://www.gov.uk){/button} test after the button" do - # rubocop:disable Layout/TrailingWhitespace - assert_html_output %{ -Text before the button - Start Now - test after the button
- } - # rubocop:enable Layout/TrailingWhitespace - assert_text_output "Text before the button Start Now test after the button" - end - test_given_govspeak "Text before the button with line breaks \n\n\n{button}[Start Now](http://www.gov.uk){/button}\n\n\n test after the button" do assert_html_output %{Text before the button with line breaks
@@ -82,4 +71,12 @@ class GovspeakTest < Minitest::Test assert_html_output '' assert_text_output "Start Now" end + + # Test indenting button govspeak results in no render, useful in guides + test_given_govspeak " {button start cross-domain-tracking:UA-XXXXXX-Y}[Example](https://example.com/external-service/start-now){/button}" do + assert_html_output %{ +{button start cross-domain-tracking:UA-XXXXXX-Y}[Example](https://example.com/external-service/start-now){/button}
+
+ }
+ end
end
diff --git a/test/html_sanitizer_test.rb b/test/html_sanitizer_test.rb
index 902a9ed8..240520bf 100644
--- a/test/html_sanitizer_test.rb
+++ b/test/html_sanitizer_test.rb
@@ -28,6 +28,14 @@ class HtmlSanitizerTest < Minitest::Test
assert_equal "Fortnum & Mason", Govspeak::HtmlSanitizer.new(html).sanitize
end
+ test "allow govspeak button markup" do
+ html = ""
+ assert_equal(
+ "",
+ Govspeak::HtmlSanitizer.new(html).sanitize
+ )
+ end
+
test "allows images on whitelisted domains" do
html = "Some text
\n