Skip to content

Commit 2aeef40

Browse files
committed
Fix tables in call to action
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.
1 parent 47aef3d commit 2aeef40

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/govspeak.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def render_image(image)
278278
extension("call-to-action", surrounded_by("$CTA")) do |body|
279279
<<~BODY
280280
<div class="call-to-action" markdown="1">
281-
#{body.strip}
281+
#{body.strip.gsub(/\A^\|/, "\n|").gsub(/\|$\Z/, "|\n")}
282282
</div>
283283
BODY
284284
end

test/govspeak_test.rb

+59
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,65 @@ class GovspeakTest < Minitest::Test
467467
<p>Here is some text</p>)
468468
end
469469

470+
test_given_govspeak "
471+
$CTA
472+
|Heading 1|Heading 2|
473+
|-|-|
474+
|information|more information|
475+
$CTA" do
476+
assert_html_output %(
477+
<div class="call-to-action">
478+
479+
<table>
480+
<thead>
481+
<tr>
482+
<th scope="col">Heading 1</th>
483+
<th scope="col">Heading 2</th>
484+
</tr>
485+
</thead>
486+
<tbody>
487+
<tr>
488+
<td>information</td>
489+
<td>more information</td>
490+
</tr>
491+
</tbody>
492+
</table>
493+
494+
</div>)
495+
end
496+
497+
test_given_govspeak "
498+
$CTA
499+
500+
### A heading within the CTA
501+
502+
|Heading 1|Heading 2|
503+
|-|-|
504+
|information|more information|
505+
506+
$CTA" do
507+
assert_html_output %(
508+
<div class="call-to-action">
509+
<h3 id="a-heading-within-the-cta">A heading within the CTA</h3>
510+
511+
<table>
512+
<thead>
513+
<tr>
514+
<th scope="col">Heading 1</th>
515+
<th scope="col">Heading 2</th>
516+
</tr>
517+
</thead>
518+
<tbody>
519+
<tr>
520+
<td>information</td>
521+
<td>more information</td>
522+
</tr>
523+
</tbody>
524+
</table>
525+
526+
</div>)
527+
end
528+
470529
test_given_govspeak "
471530
Here is some text\n
472531

0 commit comments

Comments
 (0)