Skip to content

Commit

Permalink
Merge pull request #350 from alphagov/abbr-callout
Browse files Browse the repository at this point in the history
Support acronyms within example and address blocks
  • Loading branch information
brucebolt authored Oct 4, 2024
2 parents d647005 + 75fd234 commit 64b73f5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## Unreleased
## 8.4.0

* Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
* Add support for Ruby 3.3.
* Allow acronyms within example blocks.
* Allow tables within example blocks.
* Allow acronyms within address blocks.

## 8.3.4

Expand Down
11 changes: 9 additions & 2 deletions lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,17 @@ def render_image(image)
wrap_with_div("place", "$P", Govspeak::Document)
wrap_with_div("information", "$I", Govspeak::Document)
wrap_with_div("additional-information", "$AI")
wrap_with_div("example", "$E", Govspeak::Document)

extension("example", surrounded_by("$E")) do |body|
<<~BODY
<div class="example" markdown="1">
#{body.strip.gsub(/\A^\|/, "\n|").gsub(/\|$\Z/, "|\n")}
</div>
BODY
end

extension("address", surrounded_by("$A")) do |body|
%(\n<div class="address"><div class="adr org fn"><p>\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n)
%(\n<div class="address"><div class="adr org fn"><p markdown="1">\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n)
end

extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
Expand Down
2 changes: 1 addition & 1 deletion lib/govspeak/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Govspeak
VERSION = "8.3.4".freeze
VERSION = "8.4.0".freeze
end
54 changes: 54 additions & 0 deletions test/govspeak_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,19 @@ class GovspeakTest < Minitest::Test
assert_text_output "street road"
end

test_given_govspeak "
$A
street with ACRONYM
road
$A
*[ACRONYM]: This is the acronym explanation" do
assert_html_output %(
<div class="address"><div class="adr org fn"><p>
street with <abbr title="This is the acronym explanation">ACRONYM</abbr><br>road<br>
</p></div></div>)
end

test_given_govspeak "
$P
$I
Expand Down Expand Up @@ -1247,6 +1260,47 @@ class GovspeakTest < Minitest::Test
)
end

test_given_govspeak "
$E
This is an ACRONYM.
$E
*[ACRONYM]: This is the acronym explanation
" do
assert_html_output %(
<div class="example">
<p>This is an <abbr title="This is the acronym explanation">ACRONYM</abbr>.</p>
</div>
)
end

test_given_govspeak "
$E
|Heading 1|Heading 2|
|-|-|
|information|more information|
$E" do
assert_html_output %(
<div class="example">
<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 "
$LegislativeList
* 1. Item 1[^1] with an ACRONYM
Expand Down

0 comments on commit 64b73f5

Please sign in to comment.