Skip to content

Commit

Permalink
Fix single line formatting of call to action component
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkempster34 committed Jan 24, 2024
1 parent acd0c29 commit 46c8fc7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

* Fix single line formatting of call to action component ([#302](https://github.com/alphagov/govspeak/pull/302))

## 8.3.2

* Various bug fixes related to legislative list components ([#298](https://github.com/alphagov/govspeak/pull/298))
Expand Down
4 changes: 3 additions & 1 deletion lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ def render_image(image)

extension("call-to-action", surrounded_by("$CTA")) do |body|
<<~BODY
<div class="call-to-action" markdown="1">#{body}</div>
<div class="call-to-action" markdown="1">
#{body.strip}
</div>
BODY
end

Expand Down
43 changes: 42 additions & 1 deletion test/govspeak_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %(
<div class="call-to-action">
<p>Click here to start the program</p>
</div>
<p>Here is some text</p>)
end

test_given_govspeak "
Some text
$CTA Click there to start the program $CTA
Here is some text" do
assert_html_output %(
<p>Some text</p>
<div class="call-to-action">
<p>Click there to start the program</p>
</div>
<p>Here is some text</p>)
end

test_given_govspeak "
Some text
$CTAClick anywhere to start the program$CTA
Here is some text" do
assert_html_output %(
<p>Some text</p>
<div class="call-to-action">
<p>Click anywhere to start the program</p>
</div>
<p>Here is some text</p>)
end

test_given_govspeak "
Here is some text\n
Expand Down Expand Up @@ -453,7 +495,6 @@ class GovspeakTest < Minitest::Test
$CTA" do
assert_html_output %(
<div class="call-to-action">
<p>This is a test:</p>
<ol class="steps">
Expand Down

0 comments on commit 46c8fc7

Please sign in to comment.