govspeak 8.0.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e8536931b5ec2ad23bada1b0cc94dad05779dc3d9565bc8dbd6449a6161a7a2
4
- data.tar.gz: a67ea45edba261236ce6974564a3704218e69dec860fea1e782d8d20af3922a4
3
+ metadata.gz: 0c555468b4ecde3805f07e313973dddaeadcd14383c982982294c51e804ea1da
4
+ data.tar.gz: 96053a068119e22ce4c984ab23398e069c5e0389bdc3ea4defc6401d57c1e1aa
5
5
  SHA512:
6
- metadata.gz: b66013937116e786786f240b72c61dbbbcc1e09af0fa5bfdc4b83aeef73133eb46078565dfa5766d252a9558d0b10b2322673ca0720deef7fd69414ca2ad158c
7
- data.tar.gz: dac0b4479fc4691e41356104409a93ec0802a698107c20ab17ab524042d6571d7da606111aa4b4635c4855ade81369fbfcd7db5dbb080205f3502b7423b6bfc5
6
+ metadata.gz: bae3e886909c655e6bbec31accad94c3fb1603c089e5a3208d9939ea886920d1961be65f4706e0d58c6304560970771c4507163b86f7669e4b7a798b9831d72f
7
+ data.tar.gz: 5d0a20f844cfe0c4e451b6fb0f959be7c5aa80bf95f3db2c10382f439ac28b427c10035cad2f95a79088b0d3197ea2f2e98634f1fc715f7653b7e1acba7e21db
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 8.2.0
2
+
3
+ * Reintroduce support for acronyms in Call To Action blocks and in Legislative Lists ([#285](https://github.com/alphagov/govspeak/pull/285))
4
+
5
+ ## 8.1.0
6
+
7
+ * Allow attachment links wtihin numbered lists ([#283](https://github.com/alphagov/govspeak/pull/283))
8
+
1
9
  ## 8.0.1
2
10
 
3
11
  * Add margin-bottom to embedded attachments ([#281](https://github.com/alphagov/govspeak/pull/281))
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "8.0.1".freeze
2
+ VERSION = "8.2.0".freeze
3
3
  end
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 = source.scan(/(?<=\*)\[(.*)\]:(.*)/)
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,15 +371,13 @@ 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
380
377
 
381
378
  extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body|
382
379
  body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/) do
383
- "<li>#{Govspeak::Document.new(Regexp.last_match(2).strip).to_html}</li>\n"
380
+ "<li>#{Govspeak::Document.new(Regexp.last_match(2).strip, attachments: attachments).to_html}</li>\n"
384
381
  end
385
382
  %(<ol class="steps">\n#{body}</ol>)
386
383
  end
@@ -454,10 +451,11 @@ module Govspeak
454
451
  end
455
452
 
456
453
  def add_acronym_alt_text(html)
457
- # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
458
- # @acronyms.each do |acronym|
459
- # html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
460
- # end
454
+ @acronyms.each do |acronym|
455
+ html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
456
+ end
457
+
458
+ html
461
459
  end
462
460
  end
463
461
  end
@@ -46,4 +46,28 @@ class GovspeakAttachmentLinkTest < Minitest::Test
46
46
  rendered = render_govspeak("[AttachmentLink: This is the name of my &%$@€? attachment]", [attachment])
47
47
  assert_match(/Attachment Title/, rendered)
48
48
  end
49
+
50
+ test "renders an attachment link inside a numbered list" do
51
+ attachment = {
52
+ id: "attachment.pdf",
53
+ url: "http://example.com/attachment.pdf",
54
+ title: "Attachment Title",
55
+ }
56
+
57
+ rendered = render_govspeak("s1. First item with [AttachmentLink: attachment.pdf]\ns2. Second item without attachment", [attachment])
58
+
59
+ expected_output = <<~TEXT
60
+ <ol class="steps">
61
+ <li>
62
+ <p>First item with <span class="gem-c-attachment-link">
63
+ <a class="govuk-link" href="http://example.com/attachment.pdf">Attachment Title</a> </span></p>
64
+ </li>
65
+ <li>
66
+ <p>Second item without attachment</p>
67
+ </li>
68
+ </ol>
69
+ TEXT
70
+
71
+ assert_equal(expected_output, rendered)
72
+ end
49
73
  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
@@ -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
- # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
1094
- # test_given_govspeak "
1095
- # $LegislativeList
1096
- # * 1. Item 1[^1] with an ACRONYM
1097
- # * 2. Item 2[^2]
1098
- # * 3. Item 3
1099
- # $EndLegislativeList
1100
- #
1101
- # [^1]: Footnote definition one
1102
- # [^2]: Footnote definition two with an ACRONYM
1103
- #
1104
- # *[ACRONYM]: This is the acronym explanation
1105
- # " do
1106
- # assert_html_output %(
1107
- # <ol class="legislative-list">
1108
- # <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>
1109
- # </li>
1110
- # <li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
1111
- # </li>
1112
- # <li>3. Item 3</li>
1113
- # </ol>
1114
- #
1115
- # <div class="footnotes" role="doc-endnotes">
1116
- # <ol>
1117
- # <li id="fn:1" role="doc-endnote">
1118
- # <p>
1119
- # Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1120
- # </p>
1121
- # </li>
1122
- # <li id="fn:2" role="doc-endnote">
1123
- # <p>
1124
- # 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>
1125
- # </p>
1126
- # </li>
1127
- # </ol>
1128
- # </div>
1129
- # )
1130
- # end
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.0.1
4
+ version: 8.2.0
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-07-12 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -190,14 +190,14 @@ dependencies:
190
190
  requirements:
191
191
  - - '='
192
192
  - !ruby/object:Gem::Version
193
- version: 4.11.0
193
+ version: 4.12.0
194
194
  type: :development
195
195
  prerelease: false
196
196
  version_requirements: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - '='
199
199
  - !ruby/object:Gem::Version
200
- version: 4.11.0
200
+ version: 4.12.0
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: simplecov
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -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.16
330
+ rubygems_version: 3.4.19
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Markup language for single domain