From 88b8967120531e36a562a7b6154b480e52d45f6c Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Wed, 24 Jan 2024 10:36:57 +0000 Subject: [PATCH] Fix single line formatting of call to action component We use the default mechanism for parsing the call to action component so that the parser handles abbreviations and footnotes within. Since this change (#292) we have seen a regression where defining a call to action on a single line does not work as expected (e.g., `$CTA Click here to start the program $CTA`). The closing `div` is evaluated as markdown and the call to action component therefore runs on until the next closing `div`. This can be fixed by adding in some new lines between the div tags. --- CHANGELOG.md | 4 ++++ lib/govspeak.rb | 4 +++- test/govspeak_test.rb | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10fc07a7..e0c1dc0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Fix single line formatting of call to action component + ## 8.3.2 * Various bug fixes related to legislative list components ([#298](https://github.com/alphagov/govspeak/pull/298)) diff --git a/lib/govspeak.rb b/lib/govspeak.rb index 939baca5..f49d842b 100644 --- a/lib/govspeak.rb +++ b/lib/govspeak.rb @@ -277,7 +277,9 @@ def render_image(image) extension("call-to-action", surrounded_by("$CTA")) do |body| <<~BODY -
#{body}
+
+ #{body.strip} +
BODY end diff --git a/test/govspeak_test.rb b/test/govspeak_test.rb index ae50516e..21788732 100644 --- a/test/govspeak_test.rb +++ b/test/govspeak_test.rb @@ -425,6 +425,48 @@ class GovspeakTest < Minitest::Test assert_text_output "Click here to start the tool" end + test_given_govspeak " + $CTA Click here to start the program $CTA + + Here is some text" do + assert_html_output %( +
+

Click here to start the program

+
+ +

Here is some text

) + end + + test_given_govspeak " + Some text + + $CTA Click there to start the program $CTA + + Here is some text" do + assert_html_output %( +

Some text

+
+

Click there to start the program

+
+ +

Here is some text

) + end + + test_given_govspeak " + Some text + + $CTAClick anywhere to start the program$CTA + + Here is some text" do + assert_html_output %( +

Some text

+
+

Click anywhere to start the program

+
+ +

Here is some text

) + end + test_given_govspeak " Here is some text\n @@ -453,7 +495,6 @@ class GovspeakTest < Minitest::Test $CTA" do assert_html_output %(
-

This is a test: