govspeak 6.7.3 → 6.7.7

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: a3fb6617b89131244243bd9fcc7317e6c28266122a75eb01f7e2164cd2d46775
4
- data.tar.gz: d6241111b4db6cee72273862559d27abd842a83171cd044069ca370c20f3e0e8
3
+ metadata.gz: eeb616e6f8489b589e1ddda16e92727ec5c30a9ad76b88e89184aad8590276e3
4
+ data.tar.gz: cc776bc6208ca7baafce665f4c92a549f2ee6c70fa96652e81e2ed8a32a45f5a
5
5
  SHA512:
6
- metadata.gz: 7ed67517b5fdf63bd9e5e8e95510d801ea4457ed7fb290777f72d263802b67bd9cf30a4644b99edc6c11571bd93a9b61862e076e2d68fe43973b083d6bab98df
7
- data.tar.gz: 58f86183335235a8b07cd059fe82e509e5e9701bbbbab02af250598778a720c65e136fb29e505acfe3a68727aeb09ae5e7b4d18cca20b93f67bfd3d940082fb1
6
+ metadata.gz: cb08b6e651a21f26ae42efff15d74b80401b1dc26fd516b69b02394b9eeaa20825aa4e176ef789a35ae035bb5d8be13012fb42e35c88e1e487870c81c8c4d0af
7
+ data.tar.gz: 1dc3a85af8fb5ecacb8c9a530739e8f3742fa9ea79bd3830c73c2c5d36b907d737aec74e028a4df197f11e1c0bd7d55eb25e3f5d0009a22a930cfb4e0b449f50
data/CHANGELOG.md CHANGED
@@ -1,14 +1,26 @@
1
- ## Unreleased
1
+ ## 6.7.7
2
2
 
3
- * Minimum Ruby version specified at 2.6 [215](https://github.com/alphagov/govspeak/pull/215)
3
+ * Fix broken HTML in CTA extension. [#226](https://github.com/alphagov/govspeak/pull/226)
4
+
5
+ ## 6.7.6
6
+
7
+ * Add draggable false to button markup and validation [#224](https://github.com/alphagov/govspeak/pull/224)
8
+
9
+ ## 6.7.5
10
+
11
+ * Fix footnotes in call-to-action boxes [222](https://github.com/alphagov/govspeak/pull/222)
12
+
13
+ ## 6.7.4
14
+
15
+ * Remove Nokogumbo dependency to [resolve warning](https://github.com/sparklemotion/nokogiri/issues/2205) [220](https://github.com/alphagov/govspeak/pull/220)
4
16
 
5
17
  ## 6.7.3
6
18
 
7
- * Fix regex for footnotes in legislative lists [218](
8
- https://github.com/alphagov/govspeak/pull/218
19
+ * Fix regex for footnotes in legislative lists [218](https://github.com/alphagov/govspeak/pull/218)
9
20
 
10
21
  ## 6.7.2
11
22
 
23
+ * Minimum Ruby version specified at 2.6 [215](https://github.com/alphagov/govspeak/pull/215)
12
24
  * Fix footnotes in legislative lists [216](https://github.com/alphagov/govspeak/pull/216)
13
25
 
14
26
  ## 6.7.1
@@ -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.3".freeze
2
+ VERSION = "6.7.7".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -6,7 +6,6 @@ require "htmlentities"
6
6
  require "kramdown"
7
7
  require "kramdown/parser/govuk"
8
8
  require "nokogiri"
9
- require "nokogumbo"
10
9
  require "rinku"
11
10
  require "sanitize"
12
11
  require "govspeak/header_extractor"
@@ -123,7 +122,7 @@ module Govspeak
123
122
  source = Govspeak::BlockquoteExtraQuoteRemover.remove(source)
124
123
  source = remove_forbidden_characters(source)
125
124
 
126
- legislative_list_footnote_definitions(source)
125
+ footnote_definitions(source)
127
126
 
128
127
  self.class.extensions.each do |_, regexp, block|
129
128
  source.gsub!(regexp) do
@@ -133,12 +132,12 @@ module Govspeak
133
132
  source
134
133
  end
135
134
 
136
- def legislative_list_footnote_definitions(source)
135
+ def footnote_definitions(source)
137
136
  is_legislative_list = source.scan(/\$LegislativeList.*?\[\^\d\]*.*?\$EndLegislativeList/m).size.positive?
137
+ is_cta = source.scan(/\$CTA.*?\[\^\d\]*.*?\$CTA/m).size.positive?
138
138
  footnotes = source.scan(/\[\^(\d+)\]:(.*)/)
139
139
  @acronyms = source.scan(/(?<=\*)\[(.*)\]:(.*)/)
140
-
141
- if is_legislative_list && footnotes.size.positive?
140
+ if (is_legislative_list || is_cta) && footnotes.size.positive?
142
141
  list_items = footnotes.map do |footnote|
143
142
  number = footnote[0]
144
143
  text = footnote[1].strip
@@ -225,7 +224,7 @@ module Govspeak
225
224
  text = text.strip
226
225
  href = href.strip
227
226
 
228
- %(\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)
229
228
  end
230
229
 
231
230
  extension("highlight-answer") do |body|
@@ -322,10 +321,26 @@ module Govspeak
322
321
  lines.join
323
322
  end
324
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
+
325
341
  # More specific tags must be defined first. Those defined earlier have a
326
342
  # higher precedence for being matched. For example $CTA must be defined
327
343
  # before $C otherwise the first ($C)TA fill be matched to a contact tag.
328
- wrap_with_div("call-to-action", "$CTA", Govspeak::Document)
329
344
  wrap_with_div("summary", "$!")
330
345
  wrap_with_div("form-download", "$D")
331
346
  wrap_with_div("contact", "$C")
@@ -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
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.3
4
+ version: 6.7.7
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-15 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -112,28 +112,14 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '1.5'
115
+ version: '1.12'
116
116
  type: :runtime
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '1.5'
123
- - !ruby/object:Gem::Dependency
124
- name: nokogumbo
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '2'
130
- type: :runtime
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '2'
122
+ version: '1.12'
137
123
  - !ruby/object:Gem::Dependency
138
124
  name: rinku
139
125
  requirement: !ruby/object:Gem::Requirement
@@ -152,20 +138,14 @@ dependencies:
152
138
  name: sanitize
153
139
  requirement: !ruby/object:Gem::Requirement
154
140
  requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- version: 5.2.1
158
- - - "<"
141
+ - - "~>"
159
142
  - !ruby/object:Gem::Version
160
143
  version: '6'
161
144
  type: :runtime
162
145
  prerelease: false
163
146
  version_requirements: !ruby/object:Gem::Requirement
164
147
  requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: 5.2.1
168
- - - "<"
148
+ - - "~>"
169
149
  - !ruby/object:Gem::Version
170
150
  version: '6'
171
151
  - !ruby/object:Gem::Dependency
@@ -216,14 +196,14 @@ dependencies:
216
196
  requirements:
217
197
  - - "~>"
218
198
  - !ruby/object:Gem::Version
219
- version: 4.0.0
199
+ version: 4.2.0
220
200
  type: :development
221
201
  prerelease: false
222
202
  version_requirements: !ruby/object:Gem::Requirement
223
203
  requirements:
224
204
  - - "~>"
225
205
  - !ruby/object:Gem::Version
226
- version: 4.0.0
206
+ version: 4.2.0
227
207
  - !ruby/object:Gem::Dependency
228
208
  name: simplecov
229
209
  requirement: !ruby/object:Gem::Requirement