govspeak 6.7.4 → 6.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78fc27fd0a2e9e6796195ebd2c5cc4b509d825e8c2d74cf1fb074e2dc13333a4
4
- data.tar.gz: ea33d0c2b76441a115dc891ffe638745b5afa3366318f9c90d1fb8a7d7649f5f
3
+ metadata.gz: fb4fa452bfd1c6f1cdff6b638f91dfbc9961ea2bd7568f4feadd12fe73772532
4
+ data.tar.gz: 925ff3efcbb3b3a9a1aa6e0319e9f5a3ec1540febd0168b8517c5aa884e6e69c
5
5
  SHA512:
6
- metadata.gz: 25d885461cdf12ffd1e338c1083183d7f5412b3334e3a2fce873234919643452931bb19cbf255abea5e27650a1d28d97d110ff5a43a3e60d22b1624c34e03a5b
7
- data.tar.gz: 81634215fd9936b191c6e7be565e235ea2aa1a08cf95c326a6bee088faba21ebf7d040886aead25d963430e174db67e7deff6f4aa395ca8e5f58274c6e632c14
6
+ metadata.gz: 574ea02a4f90e336a7c2a3b6642a7c1fe91924e8d71f4c55eb71053875c607c19de73aefbb34218d0cbe563c8e95982baf18ce42860a1002e58008efab20a93e
7
+ data.tar.gz: db21f5a85823c27024ff78970ec8d8dab64584910f90fdbed5649516abfbf5110fca8c52c99b978c54db3e060e1c654ac46e0995b87f5b8ab400c9dfa971b756
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 6.7.5
2
+
3
+ * Fix footnotes in call-to-action boxes [222](https://github.com/alphagov/govspeak/pull/222)
4
+
1
5
  ## 6.7.4
2
6
 
3
7
  * Remove Nokogumbo dependency to [resolve warning](https://github.com/sparklemotion/nokogiri/issues/2205) [220](https://github.com/alphagov/govspeak/pull/220)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "6.7.4".freeze
2
+ VERSION = "6.7.5".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -122,7 +122,7 @@ module Govspeak
122
122
  source = Govspeak::BlockquoteExtraQuoteRemover.remove(source)
123
123
  source = remove_forbidden_characters(source)
124
124
 
125
- legislative_list_footnote_definitions(source)
125
+ footnote_definitions(source)
126
126
 
127
127
  self.class.extensions.each do |_, regexp, block|
128
128
  source.gsub!(regexp) do
@@ -132,12 +132,12 @@ module Govspeak
132
132
  source
133
133
  end
134
134
 
135
- def legislative_list_footnote_definitions(source)
135
+ def footnote_definitions(source)
136
136
  is_legislative_list = source.scan(/\$LegislativeList.*?\[\^\d\]*.*?\$EndLegislativeList/m).size.positive?
137
+ is_cta = source.scan(/\$CTA.*?\[\^\d\]*.*?\$CTA/m).size.positive?
137
138
  footnotes = source.scan(/\[\^(\d+)\]:(.*)/)
138
139
  @acronyms = source.scan(/(?<=\*)\[(.*)\]:(.*)/)
139
-
140
- if is_legislative_list && footnotes.size.positive?
140
+ if (is_legislative_list || is_cta) && footnotes.size.positive?
141
141
  list_items = footnotes.map do |footnote|
142
142
  number = footnote[0]
143
143
  text = footnote[1].strip
@@ -321,10 +321,26 @@ module Govspeak
321
321
  lines.join
322
322
  end
323
323
 
324
+ extension("call-to-action", surrounded_by("$CTA")) do |body|
325
+ doc = Kramdown::Document.new(body.strip).to_html
326
+ doc = %(\n<div class="call-to-action">\n#{doc}</div>\n)
327
+ footnotes = body.scan(/\[\^(\d+)\]/).flatten
328
+
329
+ footnotes.each do |footnote|
330
+ html = "<sup id=\"fnref:#{footnote}\" role=\"doc-noteref\">" \
331
+ "<a href=\"#fn:#{footnote}\" class=\"footnote\" rel=\"footnote\">" \
332
+ "[footnote #{footnote}]</a></sup>"
333
+
334
+ doc.sub!(/(\[\^#{footnote}\])/, html)
335
+ end
336
+
337
+ add_acronym_alt_text(doc) if @acronyms.size.positive?
338
+ doc
339
+ end
340
+
324
341
  # More specific tags must be defined first. Those defined earlier have a
325
342
  # higher precedence for being matched. For example $CTA must be defined
326
343
  # before $C otherwise the first ($C)TA fill be matched to a contact tag.
327
- wrap_with_div("call-to-action", "$CTA", Govspeak::Document)
328
344
  wrap_with_div("summary", "$!")
329
345
  wrap_with_div("form-download", "$D")
330
346
  wrap_with_div("contact", "$C")
@@ -473,6 +473,101 @@ Teston
473
473
  </div>)
474
474
  end
475
475
 
476
+ test_given_govspeak "
477
+ $CTA
478
+ Click here to start the tool[^1]
479
+ $CTA
480
+ [^1]: Footnote definition one
481
+ " do
482
+ assert_html_output %(
483
+ <div class="call-to-action">
484
+ <p>Click here to start the tool<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup></p>
485
+ </div>
486
+ <div class="footnotes" role="doc-endnotes">
487
+ <ol>
488
+ <li id="fn:1" role="doc-endnote">
489
+ <p>
490
+ Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
491
+ </p>
492
+ </li>
493
+ </ol>
494
+ </div>
495
+ )
496
+ end
497
+
498
+ test_given_govspeak "
499
+ $CTA
500
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
501
+ Fusce felis ante[^1], lobortis non quam sit amet, tempus interdum justo.
502
+ $CTA
503
+ $CTA
504
+ Pellentesque quam enim, egestas sit amet congue sit amet[^2], ultrices vitae arcu.
505
+ Fringilla, metus dui scelerisque est.
506
+ $CTA
507
+ [^1]: Footnote definition one
508
+ [^2]: Footnote definition two
509
+ " do
510
+ assert_html_output %(
511
+ <div class="call-to-action">
512
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
513
+ Fusce felis ante<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup>, lobortis non quam sit amet, tempus interdum justo.</p>
514
+ </div>
515
+
516
+ <div class="call-to-action">
517
+ <p>Pellentesque quam enim, egestas sit amet congue sit amet<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>, ultrices vitae arcu.
518
+ Fringilla, metus dui scelerisque est.</p>
519
+ </div>
520
+ <div class="footnotes" role="doc-endnotes">
521
+ <ol>
522
+ <li id="fn:1" role="doc-endnote">
523
+ <p>
524
+ Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
525
+ </p>
526
+ </li>
527
+ <li id="fn:2" role="doc-endnote">
528
+ <p>
529
+ Footnote definition two<a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
530
+ </p>
531
+ </li>
532
+ </ol>
533
+ </div>
534
+ )
535
+ end
536
+
537
+ test_given_govspeak "
538
+ $CTA
539
+ Click here to start the tool[^1]
540
+ $CTA
541
+
542
+ Lorem ipsum dolor sit amet[^2]
543
+
544
+ [^1]: Footnote definition 1
545
+ [^2]: Footnote definition 2
546
+ " do
547
+ assert_html_output %(
548
+ <div class="call-to-action">
549
+ <p>Click here to start the tool<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup></p>
550
+ </div>
551
+
552
+ <p>Lorem ipsum dolor sit amet<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup></p>
553
+
554
+ <div class="footnotes" role="doc-endnotes">
555
+ <ol>
556
+ <li id="fn:1" role="doc-endnote">
557
+ <p>
558
+ Footnote definition 1<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
559
+ </p>
560
+ </li>
561
+ <li id="fn:2" role="doc-endnote">
562
+ <p>
563
+ Footnote definition 2<a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
564
+ </p>
565
+ </li>
566
+ </ol>
567
+ </div>
568
+ )
569
+ end
570
+
476
571
  test_given_govspeak "
477
572
  1. rod
478
573
  2. jane
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: 6.7.4
4
+ version: 6.7.5
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: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview