Skip to content

Commit

Permalink
Fix tables in call to action
Browse files Browse the repository at this point in the history
Tables must have a leading and trailing blank line in markdown. Stripping the
body of a call to action means that these are missing and tables do not render
as expected.

Therefore reinstating the blank line either side of a table contained
with a CTA.
  • Loading branch information
brucebolt committed Jan 31, 2024
1 parent 47aef3d commit 0434781
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def render_image(image)
extension("call-to-action", surrounded_by("$CTA")) do |body|
<<~BODY
<div class="call-to-action" markdown="1">
#{body.strip}
#{body.strip.gsub(/\A^\|/, "\n|").gsub(/\|$\Z/, "|\n")}
</div>
BODY
end
Expand Down
27 changes: 27 additions & 0 deletions test/govspeak_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,33 @@ class GovspeakTest < Minitest::Test
<p>Here is some text</p>)
end

test_given_govspeak "
$CTA
|Heading 1|Heading 2|
|-|-|
|information|more information|
$CTA" do
assert_html_output %(
<div class="call-to-action">
<table>
<thead>
<tr>
<th scope="col">Heading 1</th>
<th scope="col">Heading 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>information</td>
<td>more information</td>
</tr>
</tbody>
</table>
</div>)
end

test_given_govspeak "
Here is some text\n
Expand Down

0 comments on commit 0434781

Please sign in to comment.