govspeak 8.1.0 → 8.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +12 -12
- data/test/govspeak_button_test.rb +1 -1
- data/test/govspeak_test.rb +60 -38
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d49c335c68cd5f05db18037a354c1da3b1a9ad72807b41bd16dd889ed2df4f5
|
4
|
+
data.tar.gz: 12a859b126e18e44aa69e5a693508e86bb43056ea1623569cb84db51976e1985
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da16a5a2881e26fedadb229251d7d0ad6a3992828a30d142e3643026a238fd3e079b69e0a79b6a4d5b5f8645d06ef25844285a248a13fccea62afeaa53c92af7
|
7
|
+
data.tar.gz: d3fec351bc7836c657268e7fe265dc2cd331a84f858ad10620ebb7063ee9c967169563b19400075f2a3b60fd49a03df95e08f6e5c9211a686eaa29715407ded5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 8.2.1
|
2
|
+
|
3
|
+
* Prevent user error when incorrectly formatted footnotes are added to HTML attachments ([#287](https://github.com/alphagov/govspeak/pull/287))
|
4
|
+
|
5
|
+
## 8.2.0
|
6
|
+
|
7
|
+
* Reintroduce support for acronyms in Call To Action blocks and in Legislative Lists ([#285](https://github.com/alphagov/govspeak/pull/285))
|
8
|
+
|
1
9
|
## 8.1.0
|
2
10
|
|
3
11
|
* Allow attachment links wtihin numbered lists ([#283](https://github.com/alphagov/govspeak/pull/283))
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -139,12 +139,13 @@ module Govspeak
|
|
139
139
|
is_legislative_list = source.scan(/\$LegislativeList.*?\[\^\d\]*.*?\$EndLegislativeList/m).size.positive?
|
140
140
|
is_cta = source.scan(/\$CTA.*?\[\^\d\]*.*?\$CTA/m).size.positive?
|
141
141
|
footnotes = source.scan(/^\s*\[\^(\d+)\]:(.*)/)
|
142
|
-
@acronyms
|
142
|
+
@acronyms.concat(source.scan(/(?<=\*)\[(.*)\]:(.*)/))
|
143
143
|
if (is_legislative_list || is_cta) && footnotes.size.positive?
|
144
144
|
list_items = footnotes.map do |footnote|
|
145
145
|
number = footnote[0]
|
146
146
|
text = footnote[1].strip
|
147
147
|
footnote_definition = Govspeak::Document.new(text).to_html[/(?<=<p>).*(?=<\/p>)/]
|
148
|
+
footnote_definition = add_acronym_alt_text(footnote_definition)
|
148
149
|
|
149
150
|
<<~HTML_SNIPPET
|
150
151
|
<li id="fn:#{number}" role="doc-endnote">
|
@@ -163,10 +164,6 @@ module Govspeak
|
|
163
164
|
</div>
|
164
165
|
HTML_CONTAINER
|
165
166
|
end
|
166
|
-
|
167
|
-
unless @footnote_definition_html.nil? && @acronyms.size.positive?
|
168
|
-
add_acronym_alt_text(@footnote_definition_html)
|
169
|
-
end
|
170
167
|
end
|
171
168
|
|
172
169
|
def remove_forbidden_characters(source)
|
@@ -326,6 +323,7 @@ module Govspeak
|
|
326
323
|
|
327
324
|
extension("call-to-action", surrounded_by("$CTA")) do |body|
|
328
325
|
doc = Kramdown::Document.new(preprocess(body.strip), @options).to_html
|
326
|
+
doc = add_acronym_alt_text(doc)
|
329
327
|
doc = %(\n<div class="call-to-action">\n#{doc}</div>\n)
|
330
328
|
footnotes = body.scan(/\[\^(\d+)\]/).flatten
|
331
329
|
|
@@ -337,7 +335,6 @@ module Govspeak
|
|
337
335
|
doc.sub!(/(\[\^#{footnote}\])/, html)
|
338
336
|
end
|
339
337
|
|
340
|
-
add_acronym_alt_text(doc) if @acronyms.size.positive?
|
341
338
|
doc
|
342
339
|
end
|
343
340
|
|
@@ -358,6 +355,8 @@ module Govspeak
|
|
358
355
|
|
359
356
|
extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
|
360
357
|
Govspeak::KramdownOverrides.with_kramdown_ordered_lists_disabled do
|
358
|
+
body = add_acronym_alt_text(body.strip)
|
359
|
+
|
361
360
|
Kramdown::Document.new(body.strip).to_html.tap do |doc|
|
362
361
|
doc.gsub!("<ul>", "<ol>")
|
363
362
|
doc.gsub!("</ul>", "</ol>")
|
@@ -372,8 +371,6 @@ module Govspeak
|
|
372
371
|
|
373
372
|
doc.sub!(/(\[\^#{footnote}\])/, html)
|
374
373
|
end
|
375
|
-
|
376
|
-
add_acronym_alt_text(doc) if @acronyms.size.positive?
|
377
374
|
end
|
378
375
|
end
|
379
376
|
end
|
@@ -454,10 +451,13 @@ module Govspeak
|
|
454
451
|
end
|
455
452
|
|
456
453
|
def add_acronym_alt_text(html)
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
454
|
+
return unless html
|
455
|
+
|
456
|
+
@acronyms.each do |acronym|
|
457
|
+
html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
|
458
|
+
end
|
459
|
+
|
460
|
+
html
|
461
461
|
end
|
462
462
|
end
|
463
463
|
end
|
@@ -118,7 +118,7 @@ class GovspeakTest < Minitest::Test
|
|
118
118
|
" do
|
119
119
|
assert_text_output "Start now JSA"
|
120
120
|
assert_html_output %(
|
121
|
-
<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="govuk-button" draggable="false" href="https://www.apply-for-new-style-jsa.dwp.gov.uk/?lang=cy"> Start now <abbr title="Jobseeker's Allowance">JSA</abbr><svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" focusable="false" aria-hidden="true"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
|
121
|
+
<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="govuk-button" draggable="false" href="https://www.apply-for-new-style-jsa.dwp.gov.uk/?lang=cy"><span> Start now <abbr title="Jobseeker's Allowance">JSA</abbr></span><svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" focusable="false" aria-hidden="true"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
|
122
122
|
)
|
123
123
|
end
|
124
124
|
end
|
data/test/govspeak_test.rb
CHANGED
@@ -622,6 +622,21 @@ Teston
|
|
622
622
|
)
|
623
623
|
end
|
624
624
|
|
625
|
+
test_given_govspeak "
|
626
|
+
$CTA
|
627
|
+
Contact the SGD on 0800 000 0000 or contact the class on 0800 001 0001
|
628
|
+
$CTA
|
629
|
+
|
630
|
+
*[class]: Other Government Department
|
631
|
+
*[SGD]: Some Government Department
|
632
|
+
" do
|
633
|
+
assert_html_output %(
|
634
|
+
<div class="call-to-action">
|
635
|
+
<p>Contact the <abbr title="Some Government Department">SGD</abbr> on 0800 000 0000 or contact the <abbr title="Other Government Department">class</abbr> on 0800 001 0001</p>
|
636
|
+
</div>
|
637
|
+
)
|
638
|
+
end
|
639
|
+
|
625
640
|
test_given_govspeak "
|
626
641
|
1. rod
|
627
642
|
2. jane
|
@@ -1090,44 +1105,51 @@ Teston
|
|
1090
1105
|
)
|
1091
1106
|
end
|
1092
1107
|
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1108
|
+
test_given_govspeak "
|
1109
|
+
$LegislativeList
|
1110
|
+
* 1. Item 1[^1] with an ACRONYM
|
1111
|
+
* 2. Item 2[^2]
|
1112
|
+
* 3. Item 3[^3]
|
1113
|
+
$EndLegislativeList
|
1114
|
+
|
1115
|
+
[^1]: Footnote definition one
|
1116
|
+
[^2]: Footnote definition two with an ACRONYM
|
1117
|
+
[^3]: Footnote definition three with an acronym that matches an HTML tag class
|
1118
|
+
|
1119
|
+
*[ACRONYM]: This is the acronym explanation
|
1120
|
+
*[class]: Testing HTML matching
|
1121
|
+
" do
|
1122
|
+
assert_html_output %(
|
1123
|
+
<ol class="legislative-list">
|
1124
|
+
<li>1. Item 1<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup> with an <abbr title="This is the acronym explanation">ACRONYM</abbr>
|
1125
|
+
</li>
|
1126
|
+
<li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
|
1127
|
+
</li>
|
1128
|
+
<li>3. Item 3<sup id="fnref:3" role="doc-noteref"><a href="#fn:3" class="footnote" rel="footnote">[footnote 3]</a></sup>
|
1129
|
+
</li>
|
1130
|
+
</ol>
|
1131
|
+
|
1132
|
+
<div class="footnotes" role="doc-endnotes">
|
1133
|
+
<ol>
|
1134
|
+
<li id="fn:1" role="doc-endnote">
|
1135
|
+
<p>
|
1136
|
+
Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
|
1137
|
+
</p>
|
1138
|
+
</li>
|
1139
|
+
<li id="fn:2" role="doc-endnote">
|
1140
|
+
<p>
|
1141
|
+
Footnote definition two with an <abbr title="This is the acronym explanation">ACRONYM</abbr><a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
|
1142
|
+
</p>
|
1143
|
+
</li>
|
1144
|
+
<li id="fn:3" role="doc-endnote">
|
1145
|
+
<p>
|
1146
|
+
Footnote definition three with an acronym that matches an HTML tag <abbr title="Testing HTML matching">class</abbr><a href="#fnref:3" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
|
1147
|
+
</p>
|
1148
|
+
</li>
|
1149
|
+
</ol>
|
1150
|
+
</div>
|
1151
|
+
)
|
1152
|
+
end
|
1131
1153
|
|
1132
1154
|
test_given_govspeak "
|
1133
1155
|
The quick brown
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govspeak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.1
|
4
|
+
version: 8.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
327
327
|
- !ruby/object:Gem::Version
|
328
328
|
version: '0'
|
329
329
|
requirements: []
|
330
|
-
rubygems_version: 3.4.
|
330
|
+
rubygems_version: 3.4.19
|
331
331
|
signing_key:
|
332
332
|
specification_version: 4
|
333
333
|
summary: Markup language for single domain
|