govspeak 6.7.4 → 6.7.8

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: 78fc27fd0a2e9e6796195ebd2c5cc4b509d825e8c2d74cf1fb074e2dc13333a4
4
- data.tar.gz: ea33d0c2b76441a115dc891ffe638745b5afa3366318f9c90d1fb8a7d7649f5f
3
+ metadata.gz: 709c3fbb62a1b1e54cae82fd1539785acaaf3586c0a094b402880bf4608df065
4
+ data.tar.gz: 1300878c1001b40ade71a2e5446ea1f62ea8cd1e5d764e97ef9450da6124d74a
5
5
  SHA512:
6
- metadata.gz: 25d885461cdf12ffd1e338c1083183d7f5412b3334e3a2fce873234919643452931bb19cbf255abea5e27650a1d28d97d110ff5a43a3e60d22b1624c34e03a5b
7
- data.tar.gz: 81634215fd9936b191c6e7be565e235ea2aa1a08cf95c326a6bee088faba21ebf7d040886aead25d963430e174db67e7deff6f4aa395ca8e5f58274c6e632c14
6
+ metadata.gz: dcf825ebf9e77452c200104606486d9c0ad26c5f00855ce69c3c127d5e6cd7357d804fb3df77b3362fe797e814ed2cffe3823c2a835d1784e89b25c459abfd12
7
+ data.tar.gz: 607b7b974bf443801e83ec7afaab1449e00a50d63134dc90b912f62a5a5c0635ea2e54afece268dbe6c4471cc232c4f12033bef6f8961aee1816a4cd6f1fcc25
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 6.7.8
2
+
3
+ * Fixes bug which reverts acronyms from being converted into abbr tags [#229](https://github.com/alphagov/govspeak/pull/229)
4
+
5
+ ## 6.7.7
6
+
7
+ * Fix broken HTML in CTA extension. [#226](https://github.com/alphagov/govspeak/pull/226)
8
+
9
+ ## 6.7.6
10
+
11
+ * Add draggable false to button markup and validation [#224](https://github.com/alphagov/govspeak/pull/224)
12
+
13
+ ## 6.7.5
14
+
15
+ * Fix footnotes in call-to-action boxes [222](https://github.com/alphagov/govspeak/pull/222)
16
+
1
17
  ## 6.7.4
2
18
 
3
19
  * Remove Nokogumbo dependency to [resolve warning](https://github.com/sparklemotion/nokogiri/issues/2205) [220](https://github.com/alphagov/govspeak/pull/220)
data/README.md CHANGED
@@ -28,8 +28,7 @@ Once govspeak has been updated and version incremented then:
28
28
 
29
29
  Also, consider if:
30
30
  - [whitehall](https://github.com/alphagov/whitehall) needs updating (as custom govspeak changes are present)
31
- - [govuk-content-schema](https://github.com/alphagov/govuk-content-schemas) needs updating
32
- - [govpspeak-preview](https://github.com/alphagov/govspeak-preview) is worth updating
31
+ - [govpspeak-preview](https://github.com/alphagov/govspeak-preview) needs updating
33
32
 
34
33
  Any pages that use govspeak to generate Content will need to *republished* in order for the new changes to be reflected.
35
34
 
@@ -55,7 +55,7 @@ class Govspeak::HtmlSanitizer
55
55
  elements: Sanitize::Config::RELAXED[:elements] + %w[govspeak-embed-attachment govspeak-embed-attachment-link svg path].concat(allowed_elements),
56
56
  attributes: {
57
57
  :all => Sanitize::Config::RELAXED[:attributes][:all] + %w[role aria-label],
58
- "a" => Sanitize::Config::RELAXED[:attributes]["a"] + [:data],
58
+ "a" => Sanitize::Config::RELAXED[:attributes]["a"] + [:data] + %w[draggable],
59
59
  "svg" => Sanitize::Config::RELAXED[:attributes][:all] + %w[xmlns width height viewbox focusable],
60
60
  "path" => Sanitize::Config::RELAXED[:attributes][:all] + %w[fill d],
61
61
  "div" => [:data],
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "6.7.4".freeze
2
+ VERSION = "6.7.8".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
@@ -224,7 +224,7 @@ module Govspeak
224
224
  text = text.strip
225
225
  href = href.strip
226
226
 
227
- %(\n<a role="button" class="#{button_classes}" href="#{href}" #{data_attribute}>#{text}</a>\n)
227
+ %(\n<a role="button" draggable="false" class="#{button_classes}" href="#{href}" #{data_attribute}>#{text}</a>\n)
228
228
  end
229
229
 
230
230
  extension("highlight-answer") do |body|
@@ -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(preprocess(body.strip), @options).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")
@@ -448,9 +464,10 @@ module Govspeak
448
464
  end
449
465
 
450
466
  def add_acronym_alt_text(html)
451
- @acronyms.each do |acronym|
452
- html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
453
- end
467
+ # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
468
+ # @acronyms.each do |acronym|
469
+ # html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
470
+ # end
454
471
  end
455
472
  end
456
473
  end
@@ -47,7 +47,7 @@ class GovspeakTest < Minitest::Test
47
47
  assert_html_output %(
48
48
  <p>Text before the button with line breaks</p>
49
49
 
50
- <p><a class="gem-c-button govuk-button" role="button" href="http://www.gov.uk">Start Now</a></p>
50
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="http://www.gov.uk">Start Now</a></p>
51
51
 
52
52
  <p>test after the button</p>
53
53
  )
@@ -65,21 +65,21 @@ class GovspeakTest < Minitest::Test
65
65
  # Make sure button renders when typical linebreaks are before it, seen in publishing applications
66
66
  test_given_govspeak "{button}[Line breaks](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}" do
67
67
  assert_html_output %(
68
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Line breaks</a></p>
68
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Line breaks</a></p>
69
69
 
70
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
70
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
71
71
 
72
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
72
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
73
73
  )
74
74
  end
75
75
 
76
76
  test_given_govspeak "{button}[More line breaks](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}" do
77
77
  assert_html_output %(
78
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">More line breaks</a></p>
78
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">More line breaks</a></p>
79
79
 
80
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
80
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
81
81
 
82
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
82
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
83
83
  )
84
84
  end
85
85
 
@@ -104,7 +104,7 @@ class GovspeakTest < Minitest::Test
104
104
  <p>lorem lorem lorem
105
105
  lorem lorem lorem</p>
106
106
 
107
- <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Random page</a></p>
107
+ <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Random page</a></p>
108
108
 
109
109
  <p>lorem lorem lorem
110
110
  lorem lorem lorem</p>
@@ -440,6 +440,60 @@ Teston
440
440
  </div>)
441
441
  end
442
442
 
443
+ test_given_govspeak "
444
+ $CTA
445
+
446
+ This is a test:
447
+
448
+ s1. This is number 1.
449
+ s2. This is number 2.
450
+ s3. This is number 3.
451
+ s4. This is number 4.
452
+
453
+ $CTA" do
454
+ assert_html_output %(
455
+ <div class="call-to-action">
456
+ <p>This is a test:</p>
457
+
458
+ <ol class="steps">
459
+ <li>
460
+ <p>This is number 1.</p>
461
+ </li>
462
+ <li>
463
+ <p>This is number 2.</p>
464
+ </li>
465
+ <li>
466
+ <p>This is number 3.</p>
467
+ </li>
468
+ <li>
469
+ <p>This is number 4.</p>
470
+ </li>
471
+ </ol>
472
+ </div>
473
+ )
474
+ end
475
+
476
+ test_given_govspeak "
477
+ $CTA
478
+ [external link](http://www.external.com) some text
479
+ $CTA
480
+ " do
481
+ assert_html_output %(
482
+ <div class="call-to-action">
483
+ <p><a rel="external" href="http://www.external.com">external link</a> some text</p>
484
+ </div>)
485
+ end
486
+
487
+ test_given_govspeak "
488
+ $CTA
489
+ [internal link](http://www.not-external.com) some text
490
+ $CTA", document_domains: %w[www.not-external.com] do
491
+ assert_html_output %(
492
+ <div class="call-to-action">
493
+ <p><a href="http://www.not-external.com">internal link</a> some text</p>
494
+ </div>)
495
+ end
496
+
443
497
  test_given_govspeak "
444
498
  $CTA
445
499
  Click here to start the tool
@@ -473,6 +527,101 @@ Teston
473
527
  </div>)
474
528
  end
475
529
 
530
+ test_given_govspeak "
531
+ $CTA
532
+ Click here to start the tool[^1]
533
+ $CTA
534
+ [^1]: Footnote definition one
535
+ " do
536
+ assert_html_output %(
537
+ <div class="call-to-action">
538
+ <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>
539
+ </div>
540
+ <div class="footnotes" role="doc-endnotes">
541
+ <ol>
542
+ <li id="fn:1" role="doc-endnote">
543
+ <p>
544
+ Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
545
+ </p>
546
+ </li>
547
+ </ol>
548
+ </div>
549
+ )
550
+ end
551
+
552
+ test_given_govspeak "
553
+ $CTA
554
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
555
+ Fusce felis ante[^1], lobortis non quam sit amet, tempus interdum justo.
556
+ $CTA
557
+ $CTA
558
+ Pellentesque quam enim, egestas sit amet congue sit amet[^2], ultrices vitae arcu.
559
+ Fringilla, metus dui scelerisque est.
560
+ $CTA
561
+ [^1]: Footnote definition one
562
+ [^2]: Footnote definition two
563
+ " do
564
+ assert_html_output %(
565
+ <div class="call-to-action">
566
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
567
+ 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>
568
+ </div>
569
+
570
+ <div class="call-to-action">
571
+ <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.
572
+ Fringilla, metus dui scelerisque est.</p>
573
+ </div>
574
+ <div class="footnotes" role="doc-endnotes">
575
+ <ol>
576
+ <li id="fn:1" role="doc-endnote">
577
+ <p>
578
+ Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
579
+ </p>
580
+ </li>
581
+ <li id="fn:2" role="doc-endnote">
582
+ <p>
583
+ Footnote definition two<a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
584
+ </p>
585
+ </li>
586
+ </ol>
587
+ </div>
588
+ )
589
+ end
590
+
591
+ test_given_govspeak "
592
+ $CTA
593
+ Click here to start the tool[^1]
594
+ $CTA
595
+
596
+ Lorem ipsum dolor sit amet[^2]
597
+
598
+ [^1]: Footnote definition 1
599
+ [^2]: Footnote definition 2
600
+ " do
601
+ assert_html_output %(
602
+ <div class="call-to-action">
603
+ <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>
604
+ </div>
605
+
606
+ <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>
607
+
608
+ <div class="footnotes" role="doc-endnotes">
609
+ <ol>
610
+ <li id="fn:1" role="doc-endnote">
611
+ <p>
612
+ Footnote definition 1<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
613
+ </p>
614
+ </li>
615
+ <li id="fn:2" role="doc-endnote">
616
+ <p>
617
+ Footnote definition 2<a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
618
+ </p>
619
+ </li>
620
+ </ol>
621
+ </div>
622
+ )
623
+ end
624
+
476
625
  test_given_govspeak "
477
626
  1. rod
478
627
  2. jane
@@ -899,43 +1048,44 @@ Teston
899
1048
  )
900
1049
  end
901
1050
 
902
- test_given_govspeak "
903
- $LegislativeList
904
- * 1. Item 1[^1] with an ACRONYM
905
- * 2. Item 2[^2]
906
- * 3. Item 3
907
- $EndLegislativeList
908
-
909
- [^1]: Footnote definition one
910
- [^2]: Footnote definition two with an ACRONYM
911
-
912
- *[ACRONYM]: This is the acronym explanation
913
- " do
914
- assert_html_output %(
915
- <ol class="legislative-list">
916
- <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>
917
- </li>
918
- <li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
919
- </li>
920
- <li>3. Item 3</li>
921
- </ol>
922
-
923
- <div class="footnotes" role="doc-endnotes">
924
- <ol>
925
- <li id="fn:1" role="doc-endnote">
926
- <p>
927
- Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
928
- </p>
929
- </li>
930
- <li id="fn:2" role="doc-endnote">
931
- <p>
932
- 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>
933
- </p>
934
- </li>
935
- </ol>
936
- </div>
937
- )
938
- end
1051
+ # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
1052
+ # test_given_govspeak "
1053
+ # $LegislativeList
1054
+ # * 1. Item 1[^1] with an ACRONYM
1055
+ # * 2. Item 2[^2]
1056
+ # * 3. Item 3
1057
+ # $EndLegislativeList
1058
+ #
1059
+ # [^1]: Footnote definition one
1060
+ # [^2]: Footnote definition two with an ACRONYM
1061
+ #
1062
+ # *[ACRONYM]: This is the acronym explanation
1063
+ # " do
1064
+ # assert_html_output %(
1065
+ # <ol class="legislative-list">
1066
+ # <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>
1067
+ # </li>
1068
+ # <li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
1069
+ # </li>
1070
+ # <li>3. Item 3</li>
1071
+ # </ol>
1072
+ #
1073
+ # <div class="footnotes" role="doc-endnotes">
1074
+ # <ol>
1075
+ # <li id="fn:1" role="doc-endnote">
1076
+ # <p>
1077
+ # Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1078
+ # </p>
1079
+ # </li>
1080
+ # <li id="fn:2" role="doc-endnote">
1081
+ # <p>
1082
+ # 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>
1083
+ # </p>
1084
+ # </li>
1085
+ # </ol>
1086
+ # </div>
1087
+ # )
1088
+ # end
939
1089
 
940
1090
  test_given_govspeak "
941
1091
  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: 6.7.4
4
+ version: 6.7.8
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: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -196,14 +196,14 @@ dependencies:
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: 4.1.0
199
+ version: 4.2.0
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
- version: 4.1.0
206
+ version: 4.2.0
207
207
  - !ruby/object:Gem::Dependency
208
208
  name: simplecov
209
209
  requirement: !ruby/object:Gem::Requirement