From 8f7b9528d9a864c5dabd2378be693f2c5639f985 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 so that the parser can handle abbreviations and footnotes inside call to action component. Since this change (#292) we have had 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 | 13 ++++++++++++- 3 files changed, 19 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..a4446325 100644 --- a/test/govspeak_test.rb +++ b/test/govspeak_test.rb @@ -425,6 +425,18 @@ 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 " Here is some text\n @@ -453,7 +465,6 @@ class GovspeakTest < Minitest::Test $CTA" do assert_html_output %(
-

This is a test: