govspeak 6.8.4 → 7.0.1

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: 35ed6a74578a19fb89e4c855494d27708d7809e925a6029b5b391fbe474f5d49
4
- data.tar.gz: 74f0b44824ff948767ae8e8f1a5f95ae784f07ea3ab424f66a46ee0d07efb6af
3
+ metadata.gz: 8013e06cbc3f6f61be8953690c30bf05999ee7b405127bf9ab05566021dff5d6
4
+ data.tar.gz: d0db3c14af86be0a18662a1aacc9d6f058e0e72295957c478206e41dc97ca06f
5
5
  SHA512:
6
- metadata.gz: c022e6a898d40e41ea571d9f39863f6235822810d2823f99d17e58eb559ab7e0b2b35c2a60cdec627270b9fe3d31c39224f820e5e8f3378f8df811478ca6203d
7
- data.tar.gz: facb052f32abfcdc7e54fb6799d7e052d1a951aedce6db6b582fa716654bb6cc6730ff99af65a2af511dc0039b4f07f8f9669accbadf8821b01f2280c22933c8
6
+ metadata.gz: 07aedd1b981eb39f4b13327cb1192b598fbd0b90a1fc5f0a3c85d05e9baa428022435fe1891cbd576b824f410b5f9daf68b96d0742dfbdc05abcda1b946cdb9d
7
+ data.tar.gz: 75f8333f15d52a9e4e358abf8319daf1e05a2800f347937f2b63c52f1d860d691b30b72013ad07e310e2f9926ed63a8b344b5509271a9161a5a307353ea6feaf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 7.0.1
2
+
3
+ * Govspeak was stripping superscript from markdown when it shouldn't have. [#264](https://github.com/alphagov/govspeak/pull/264)
4
+
5
+ ## 7.0.0
6
+
7
+ * BREAKING CHANGE Remove `PriorityList`, the `PrimaryList` JS module to render the priority list on the frontend is to be removed [#249](https://github.com/alphagov/govspeak/pull/249)
8
+
1
9
  ## 6.8.4
2
10
 
3
11
  * Fix bug where inconsistent linebreaks trigger validations [#250](https://github.com/alphagov/govspeak/pull/250)
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ..gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -292,29 +292,6 @@ For lists where you want to specify the numbering and have multiple indent level
292
292
  $EndLegislativeList
293
293
  (to indent, add 2 spaces)
294
294
 
295
- ## Priority Lists
296
-
297
- For lists where you want to specify a number of items to be highlighted as priority.
298
-
299
- $PriorityList:3
300
- - Item 1
301
- - Item 2
302
- - Item 3
303
- - Item 4
304
- - Item 5
305
-
306
- creates a list with priority items flagged with a class
307
-
308
- ```html
309
- <ul>
310
- <li class="primary-item">Item 1</li>
311
- <li class="primary-item">Item 2</li>
312
- <li class="primary-item">Item 3</li>
313
- <li>Item 4</li>
314
- <li>Item 5</li>
315
- </ul>
316
- ```
317
-
318
295
  ## Devolved content
319
296
 
320
297
  :england:content goes here:england:
@@ -692,4 +669,9 @@ which outputs
692
669
  Start Now
693
670
  <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg>
694
671
  </a>
695
- ```
672
+ ```
673
+
674
+ ## Licence
675
+
676
+ [MIT License](LICENCE)
677
+
@@ -85,20 +85,20 @@ module Govspeak
85
85
 
86
86
  extension("Add table headers and row / column scopes") do |document|
87
87
  document.css("thead th").map do |el|
88
- el.content = el.content.gsub(/^# /, "")
89
- el.content = el.content.gsub(/[[:space:]]/, "") if el.content.blank? # Removes a strange whitespace in the cell if the cell is already blank.
90
- el.name = "td" if el.content.blank? # This prevents a `th` with nothing inside it; a `td` is preferable.
91
- el[:scope] = "col" if el.content.present? # `scope` shouldn't be used if there's nothing in the table heading.
88
+ el.inner_html = el.inner_html.gsub(/^# /, "")
89
+ el.inner_html = el.inner_html.gsub(/[[:space:]]/, "") if el.inner_html.blank? # Removes a strange whitespace in the cell if the cell is already blank.
90
+ el.name = "td" if el.inner_html.blank? # This prevents a `th` with nothing inside it; a `td` is preferable.
91
+ el[:scope] = "col" if el.inner_html.present? # `scope` shouldn't be used if there's nothing in the table heading.
92
92
  end
93
93
 
94
94
  document.css(":not(thead) tr td:first-child").map do |el|
95
- next unless el.content.match?(/^#($|\s.*$)/)
95
+ next unless el.inner_html.match?(/^#($|\s.*$)/)
96
96
 
97
97
  # Replace '# ' and '#', but not '#Word'.
98
98
  # This runs on the first child of the element to preserve any links
99
99
  el.children.first.content = el.children.first.content.gsub(/^#($|\s)/, "")
100
- el.name = "th" if el.content.present? # This also prevents a `th` with nothing inside it; a `td` is preferable.
101
- el[:scope] = "row" if el.content.present? # `scope` shouldn't be used if there's nothing in the table heading.
100
+ el.name = "th" if el.inner_html.present? # This also prevents a `th` with nothing inside it; a `td` is preferable.
101
+ el[:scope] = "row" if el.inner_html.present? # `scope` shouldn't be used if there's nothing in the table heading.
102
102
  end
103
103
  end
104
104
 
@@ -106,7 +106,7 @@ module Govspeak
106
106
  document.css(".govuk-button").map do |el|
107
107
  button_html = GovukPublishingComponents.render(
108
108
  "govuk_publishing_components/components/button",
109
- text: el.content,
109
+ text: el.inner_html,
110
110
  href: el["href"],
111
111
  start: el["data-start"],
112
112
  data_attributes: {
@@ -123,7 +123,7 @@ module Govspeak
123
123
  extension("use custom footnotes") do |document|
124
124
  document.css("a.footnote").map do |el|
125
125
  footnote_number = el[:href].gsub(/\D/, "")
126
- el.content = "[footnote #{footnote_number}]"
126
+ el.inner_html = "[footnote #{footnote_number}]"
127
127
  end
128
128
  document.css("[role='doc-backlink']").map do |el|
129
129
  backlink_number = " #{el.css('sup')[0].content}" if el.css("sup")[0].present?
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "6.8.4".freeze
2
+ VERSION = "7.0.1".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -405,19 +405,6 @@ module Govspeak
405
405
  end
406
406
  end
407
407
 
408
- extension("Priority list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$PriorityList:(\d+)\s*$(.*?)(?:^\s*$|\Z)/m) do |number_to_show, body|
409
- number_to_show = number_to_show.to_i
410
- tagged = 0
411
- Govspeak::Document.new(body.strip).to_html.gsub(/<li>/) do |match|
412
- if tagged < number_to_show
413
- tagged += 1
414
- '<li class="primary-item">'
415
- else
416
- match
417
- end
418
- end
419
- end
420
-
421
408
  extension("embed link", /\[embed:link:\s*(.*?)\s*\]/) do |content_id|
422
409
  link = links.detect { |l| l[:content_id] == content_id }
423
410
  next "" unless link
@@ -7,18 +7,18 @@ class GovspeakTest < Minitest::Test
7
7
  include GovspeakTestHelper
8
8
 
9
9
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
10
- assert_html_selector 'a.gem-c-button.govuk-button--start[data-module="cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
10
+ assert_html_selector 'a.gem-c-button.govuk-button--start[data-module="govuk-button cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
11
11
  assert_text_output "Start now"
12
12
  end
13
13
 
14
14
  # The same as above but with line breaks
15
15
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}\n\n\n[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start)\n\n\n{/button}" do
16
- assert_html_selector 'a.gem-c-button.govuk-button--start[data-module="cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
16
+ assert_html_selector 'a.gem-c-button.govuk-button--start[data-module="govuk-button cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
17
17
  assert_text_output "Start now"
18
18
  end
19
19
 
20
20
  test_given_govspeak "{button cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
21
- assert_html_selector 'a.gem-c-button:not(.govuk-button--start)[data-module="cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
21
+ assert_html_selector 'a.gem-c-button:not(.govuk-button--start)[data-module="govuk-button cross-domain-tracking"][data-tracking-code="UA-23066786-5"][href="https://www.registertovote.service.gov.uk/register-to-vote/start"]'
22
22
  assert_text_output "Start now"
23
23
  end
24
24
 
@@ -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" draggable="false" href="http://www.gov.uk">Start Now</a></p>
50
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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" draggable="false" href="https://gov.uk/random">Line breaks</a></p>
68
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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" draggable="false" href="https://gov.uk/random">Continue</a></p>
70
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-button" draggable="false" href="https://gov.uk/random">Continue</a></p>
71
71
 
72
- <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
72
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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" draggable="false" href="https://gov.uk/random">More line breaks</a></p>
78
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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" draggable="false" href="https://gov.uk/random">Continue</a></p>
80
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-button" draggable="false" href="https://gov.uk/random">Continue</a></p>
81
81
 
82
- <p><a class="gem-c-button govuk-button" role="button" draggable="false" href="https://gov.uk/random">Continue</a></p>
82
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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" draggable="false" href="https://gov.uk/random">Random page</a></p>
107
+ <p><a class="gem-c-button govuk-button" role="button" data-module="govuk-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>
@@ -131,6 +131,34 @@ class GovspeakTableWithHeadersTest < Minitest::Test
131
131
  )
132
132
  end
133
133
 
134
+ def expected_outcome_for_table_with_table_headers_containing_superscript
135
+ %(
136
+ <table>
137
+ <thead>
138
+ <tr>
139
+ <th scope="col">Foo<sup>bar</sup>
140
+ </th>
141
+ <th scope="col">Third Column</th>
142
+ </tr>
143
+ </thead>
144
+ <tbody>
145
+ <tr>
146
+ <td>Cell</td>
147
+ <td>Cell</td>
148
+ </tr>
149
+ </tbody>
150
+ </table>
151
+ )
152
+ end
153
+
154
+ def document_body_with_table_headers_containing_superscript
155
+ @document_body_with_table_headers_containing_superscript ||= Govspeak::Document.new(%(
156
+ | Foo<sup>bar</sup> | Third Column |
157
+ | --------------- | ------------------- |
158
+ | Cell | Cell |
159
+ ))
160
+ end
161
+
134
162
  def expected_outcome_for_table_headers_containing_links
135
163
  %(
136
164
  <table>
@@ -242,4 +270,8 @@ class GovspeakTableWithHeadersTest < Minitest::Test
242
270
  test "Table headers are not blank" do
243
271
  assert_equal document_body_with_blank_table_headers.to_html, expected_outcome_for_table_with_blank_table_headers
244
272
  end
273
+
274
+ test "Table header superscript should parse" do
275
+ assert_equal document_body_with_table_headers_containing_superscript.to_html, expected_outcome_for_table_with_table_headers_containing_superscript
276
+ end
245
277
  end
@@ -1219,139 +1219,6 @@ Teston
1219
1219
  assert document.valid?
1220
1220
  end
1221
1221
 
1222
- expected_priority_list_output = %(
1223
- <ul>
1224
- <li class="primary-item">List item 1</li>
1225
- <li class="primary-item">List item 2</li>
1226
- <li class="primary-item">List item 3</li>
1227
- <li>List item 4</li>
1228
- <li>List item 5</li>
1229
- </ul>
1230
- )
1231
-
1232
- test "Single priority list ending with EOF" do
1233
- govspeak = "$PriorityList:3
1234
- * List item 1
1235
- * List item 2
1236
- * List item 3
1237
- * List item 4
1238
- * List item 5"
1239
-
1240
- given_govspeak(govspeak) do
1241
- assert_html_output(expected_priority_list_output)
1242
- end
1243
- end
1244
-
1245
- test "Single priority list ending with newlines" do
1246
- govspeak = "$PriorityList:3
1247
- * List item 1
1248
- * List item 2
1249
- * List item 3
1250
- * List item 4
1251
- * List item 5
1252
-
1253
- "
1254
-
1255
- given_govspeak(govspeak) do
1256
- assert_html_output(expected_priority_list_output)
1257
- end
1258
- end
1259
-
1260
- test 'Single priority list with \n newlines' do
1261
- govspeak = "$PriorityList:3\n * List item 1\n * List item 2\n * List item 3\n * List item 4\n * List item 5"
1262
-
1263
- given_govspeak(govspeak) do
1264
- assert_html_output(expected_priority_list_output)
1265
- end
1266
- end
1267
-
1268
- test 'Single priority list with \r\n newlines' do
1269
- govspeak = "$PriorityList:3\r\n * List item 1\r\n * List item 2\r\n * List item 3\r\n * List item 4\r\n * List item 5"
1270
-
1271
- given_govspeak(govspeak) do
1272
- assert_html_output(expected_priority_list_output)
1273
- end
1274
- end
1275
-
1276
- test "Multiple priority lists" do
1277
- govspeak = "
1278
- $PriorityList:3
1279
- * List item 1
1280
- * List item 2
1281
- * List item 3
1282
- * List item 4
1283
- * List item 5
1284
-
1285
- $PriorityList:1
1286
- * List item 1
1287
- * List item 2"
1288
-
1289
- given_govspeak(govspeak) do
1290
- assert_html_output %(
1291
- <ul>
1292
- <li class="primary-item">List item 1</li>
1293
- <li class="primary-item">List item 2</li>
1294
- <li class="primary-item">List item 3</li>
1295
- <li>List item 4</li>
1296
- <li>List item 5</li>
1297
- </ul>
1298
-
1299
- <ul>
1300
- <li class="primary-item">List item 1</li>
1301
- <li>List item 2</li>
1302
- </ul>
1303
- )
1304
- end
1305
- end
1306
-
1307
- test "Priority list placed incorrectly" do
1308
- govspeak = "
1309
- This is a paragraph
1310
- $PriorityList:3
1311
- * List item 1
1312
- * List item 2
1313
- * List item 3
1314
- * List item 4
1315
- * List item 5"
1316
-
1317
- given_govspeak(govspeak) do
1318
- assert_html_output("
1319
- <p>This is a paragraph
1320
- $PriorityList:3
1321
- * List item 1
1322
- * List item 2
1323
- * List item 3
1324
- * List item 4
1325
- * List item 5</p>")
1326
- end
1327
- end
1328
-
1329
- test "Priority list placed correctly" do
1330
- govspeak = "
1331
- This is a paragraph
1332
-
1333
- $PriorityList:3
1334
- * List item 1
1335
- * List item 2
1336
- * List item 3
1337
- * List item 4
1338
- * List item 5"
1339
-
1340
- given_govspeak(govspeak) do
1341
- assert_html_output %(
1342
- <p>This is a paragraph</p>
1343
-
1344
- <ul>
1345
- <li class="primary-item">List item 1</li>
1346
- <li class="primary-item">List item 2</li>
1347
- <li class="primary-item">List item 3</li>
1348
- <li>List item 4</li>
1349
- <li>List item 5</li>
1350
- </ul>
1351
- )
1352
- end
1353
- end
1354
-
1355
1222
  test "should remove quotes surrounding a blockquote" do
1356
1223
  govspeak = %(
1357
1224
  He said:
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.8.4
4
+ version: 7.0.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: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2022-12-16 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.6.0
193
+ version: 4.9.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.6.0
200
+ version: 4.9.0
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: simplecov
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -327,29 +327,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  - !ruby/object:Gem::Version
328
328
  version: '0'
329
329
  requirements: []
330
- rubygems_version: 3.3.20
330
+ rubygems_version: 3.3.26
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Markup language for single domain
334
334
  test_files:
335
- - test/govspeak_attachments_image_test.rb
336
- - test/govspeak_link_extractor_test.rb
337
- - test/govspeak_table_with_headers_test.rb
338
- - test/govspeak_attachment_test.rb
339
- - test/govspeak_extract_contact_content_ids_test.rb
335
+ - test/blockquote_extra_quote_remover_test.rb
336
+ - test/govspeak_attachment_link_test.rb
337
+ - test/govspeak_images_test.rb
340
338
  - test/test_helper.rb
341
- - test/html_validator_test.rb
342
- - test/govspeak_test_helper.rb
343
- - test/html_sanitizer_test.rb
344
339
  - test/govspeak_footnote_test.rb
345
- - test/govspeak_images_test.rb
346
340
  - test/govspeak_button_test.rb
341
+ - test/govspeak_link_test.rb
342
+ - test/html_sanitizer_test.rb
347
343
  - test/govspeak_test.rb
348
- - test/blockquote_extra_quote_remover_test.rb
344
+ - test/govspeak_table_with_headers_test.rb
345
+ - test/html_validator_test.rb
346
+ - test/govspeak_attachments_image_test.rb
349
347
  - test/govspeak_images_bang_test.rb
348
+ - test/govspeak_link_extractor_test.rb
350
349
  - test/presenters/h_card_presenter_test.rb
351
- - test/govspeak_contacts_test.rb
352
- - test/govspeak_attachment_link_test.rb
353
- - test/govspeak_attachments_inline_test.rb
354
- - test/govspeak_link_test.rb
350
+ - test/govspeak_test_helper.rb
351
+ - test/govspeak_attachment_test.rb
355
352
  - test/govspeak_structured_headers_test.rb
353
+ - test/govspeak_attachments_inline_test.rb
354
+ - test/govspeak_contacts_test.rb
355
+ - test/govspeak_extract_contact_content_ids_test.rb