govspeak 7.0.2 → 7.1.1

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: 14fa86649f2bb73e47685e2fb16ae978b1dff2a3f7bef496fd7520186547d854
4
- data.tar.gz: 203651a48459e58f8974a4621ba3ea0651133077c79b94d0cbf489df8049ceae
3
+ metadata.gz: 8b23cb6b80ef9b9d71a55b5cf0c1ffa1d33c3127ebac6290e7ed57de253439bd
4
+ data.tar.gz: 5bbe38f1188c1159d7af520b22dc2fc011e95256c53be222170081220c11fa64
5
5
  SHA512:
6
- metadata.gz: 4f9af0743b85af02263ece3934eb4b8df41b25f1dad626bfd65216dd405110b66c08bf32cbcf1c44a93a0678d8934131e37ec0ca66e37148516d9e3e3ca25ff2
7
- data.tar.gz: 175745b808a77d6d7a60b85b617b1df9596c5c2483d0fac784c1d8c42a2eaea71ee2dc7ffdd0f5968417126b97fea0a1583c70598793795da08bd821fa7b1c21
6
+ metadata.gz: 13e3cbc3237ad2b739ff8d984d35e040e1379e716791fb9ed7d789b4d4ca9ce6398a53cb8bf095df68af80257aa5d1e2659803857f88677073576685da65df60
7
+ data.tar.gz: 0f9dc64d2983ffa7c546d54f96c852500d92b2b01e2b48d163784b5d41a2a6e38202d8385665c264287b8035d0b8d96059a5fd0be7f065774d602b3caeefc84b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
+ ## 7.1.1
2
+
3
+ * Make image and attachment embedding syntax more consistent [#274](https://github.com/alphagov/govspeak/pull/274)
4
+
5
+ ## 7.1.0
6
+
7
+ * Drop support for Ruby 2.7 [#272](https://github.com/alphagov/govspeak/pull/272)
8
+ * Replace inline style attributes in td/th elements with classes [#268](https://github.com/alphagov/govspeak/pull/268)
9
+
1
10
  ## 7.0.2
2
11
 
3
- * Fix for abbreviations nested in button. [#267] (https://github.com/alphagov/govspeak/pull/267)
12
+ * Fix for abbreviations nested in button. [#267](https://github.com/alphagov/govspeak/pull/267)
4
13
 
5
14
  ## 7.0.1
6
15
 
@@ -69,6 +69,8 @@ class Govspeak::HtmlSanitizer
69
69
  "svg" => Sanitize::Config::RELAXED[:attributes][:all] + %w[xmlns width height viewbox focusable],
70
70
  "path" => Sanitize::Config::RELAXED[:attributes][:all] + %w[fill d],
71
71
  "div" => [:data],
72
+ # @TODO These style attributes can be removed once we've checked there
73
+ # isn't hardcoded HTML in documents that uses them
72
74
  "th" => Sanitize::Config::RELAXED[:attributes]["th"] + %w[style],
73
75
  "td" => Sanitize::Config::RELAXED[:attributes]["td"] + %w[style],
74
76
  "govspeak-embed-attachment" => %w[content-id],
@@ -102,6 +102,23 @@ module Govspeak
102
102
  end
103
103
  end
104
104
 
105
+ extension("convert table cell inline styles to classes") do |document|
106
+ document.css("th[style], td[style]").each do |el|
107
+ style = el.remove_attribute("style")
108
+ matches = style.value.scan(/text-align:\s*(left|center|right)/).flatten
109
+
110
+ next unless matches.any?
111
+
112
+ class_name = "cell-text-#{matches.last}"
113
+
114
+ if el[:class]
115
+ el[:class] += " #{class_name}"
116
+ else
117
+ el[:class] = class_name
118
+ end
119
+ end
120
+ end
121
+
105
122
  extension("use gem component for buttons") do |document|
106
123
  document.css(".govuk-button").map do |el|
107
124
  button_html = GovukPublishingComponents.render(
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "7.0.2".freeze
2
+ VERSION = "7.1.1".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -32,7 +32,7 @@ module Govspeak
32
32
  class Document
33
33
  Parser = Kramdown::Parser::Govuk
34
34
  PARSER_CLASS_NAME = Parser.name.split("::").last
35
- UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.freeze
35
+ UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
36
36
  NEW_PARAGRAPH_LOOKBEHIND = %q{(?<=\A|\n\n|\r\n\r\n)}.freeze
37
37
 
38
38
  @extensions = []
@@ -424,14 +424,14 @@ module Govspeak
424
424
  renderer.render(contact: ContactPresenter.new(contact))
425
425
  end
426
426
 
427
- extension("Image", /#{NEW_PARAGRAPH_LOOKBEHIND}\[Image:\s*(.*?)\s*\]/) do |image_id|
427
+ extension("Image", /^\[Image:\s*(.*?)\s*\]/) do |image_id|
428
428
  image = images.detect { |c| c.is_a?(Hash) && c[:id] == image_id }
429
429
  next "" unless image
430
430
 
431
431
  render_image(ImagePresenter.new(image))
432
432
  end
433
433
 
434
- extension("Attachment", /#{NEW_PARAGRAPH_LOOKBEHIND}\[Attachment:\s*(.*?)\s*\]/) do |attachment_id|
434
+ extension("Attachment", /^\[Attachment:\s*(.*?)\s*\]/) do |attachment_id|
435
435
  next "" if attachments.none? { |a| a[:id] == attachment_id }
436
436
 
437
437
  %(<govspeak-embed-attachment id="#{attachment_id}"></govspeak-embed-attachment>)
@@ -21,7 +21,7 @@ class GovspeakAttachmentTest < Minitest::Test
21
21
  assert_match(/Attachment Title/, rendered)
22
22
  end
23
23
 
24
- test "only renders attachment when markdown extension starts on a line" do
24
+ test "only renders attachment when markdown extension starts on a new line" do
25
25
  attachment = {
26
26
  id: "attachment.pdf",
27
27
  url: "http://example.com/attachment.pdf",
@@ -34,5 +34,10 @@ class GovspeakAttachmentTest < Minitest::Test
34
34
  rendered = render_govspeak("[Attachment:attachment.pdf] some text", [attachment])
35
35
  assert_match(/<section class="gem-c-attachment/, rendered)
36
36
  assert_match(/<p>some text<\/p>/, rendered)
37
+
38
+ rendered = render_govspeak("some text\n[Attachment:attachment.pdf]\nsome more text", [attachment])
39
+ assert_match(/<p>some text<\/p>/, rendered)
40
+ assert_match(/<section class="gem-c-attachment/, rendered)
41
+ assert_match(/<p>some more text<\/p>/, rendered)
37
42
  end
38
43
  end
@@ -80,4 +80,30 @@ class GovspeakImagesBangTest < Minitest::Test
80
80
  )
81
81
  end
82
82
  end
83
+
84
+ test "!!n syntax must start on a new line" do
85
+ given_govspeak "some text !!1", images: [Image.new] do
86
+ assert_html_output("<p>some text !!1</p>")
87
+ end
88
+
89
+ given_govspeak "!!1", images: [Image.new] do
90
+ assert_html_output(
91
+ "<figure class=\"image embedded\"><div class=\"img\"><img src=\"http://example.com/image.jpg\" alt=\"my alt\"></div></figure>",
92
+ )
93
+ end
94
+
95
+ given_govspeak "!!1 some text", images: [Image.new] do
96
+ assert_html_output(
97
+ "<figure class=\"image embedded\"><div class=\"img\"><img src=\"http://example.com/image.jpg\" alt=\"my alt\"></div></figure>\n<p>some text</p>",
98
+ )
99
+ end
100
+
101
+ given_govspeak "some text\n!!1\nsome more text", images: [Image.new] do
102
+ assert_html_output <<~HTML
103
+ <p>some text</p>
104
+ <figure class="image embedded"><div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div></figure>
105
+ <p>some more text</p>
106
+ HTML
107
+ end
108
+ end
83
109
  end
@@ -88,5 +88,13 @@ class GovspeakImagesTest < Minitest::Test
88
88
  "<figure class=\"image embedded\"><div class=\"img\"><img src=\"http://example.com/image.jpg\" alt=\"my alt\"></div></figure>\n<p>some text</p>",
89
89
  )
90
90
  end
91
+
92
+ given_govspeak "some text\n[Image:image-id]\nsome more text", images: [build_image] do
93
+ assert_html_output <<~HTML
94
+ <p>some text</p>
95
+ <figure class="image embedded"><div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div></figure>
96
+ <p>some more text</p>
97
+ HTML
98
+ end
91
99
  end
92
100
  end
@@ -58,21 +58,21 @@ class GovspeakTableWithHeadersTest < Minitest::Test
58
58
  <table>
59
59
  <thead>
60
60
  <tr>
61
- <td style="text-align: left"></td>
62
- <th style="text-align: center" scope="col">Second Column</th>
63
- <th style="text-align: right" scope="col">Third Column</th>
61
+ <td class="cell-text-left"></td>
62
+ <th scope="col" class="cell-text-center">Second Column</th>
63
+ <th scope="col" class="cell-text-right">Third Column</th>
64
64
  </tr>
65
65
  </thead>
66
66
  <tbody>
67
67
  <tr>
68
- <th style="text-align: left" scope="row">First row</th>
69
- <td style="text-align: center">Cell</td>
70
- <td style="text-align: right">Cell</td>
68
+ <th scope="row" class="cell-text-left">First row</th>
69
+ <td class="cell-text-center">Cell</td>
70
+ <td class="cell-text-right">Cell</td>
71
71
  </tr>
72
72
  <tr>
73
- <th style="text-align: left" scope="row">Second row</th>
74
- <td style="text-align: center">Cell</td>
75
- <td style="text-align: right">Cell</td>
73
+ <th scope="row" class="cell-text-left">Second row</th>
74
+ <td class="cell-text-center">Cell</td>
75
+ <td class="cell-text-right">Cell</td>
76
76
  </tr>
77
77
  </tbody>
78
78
  </table>
@@ -255,7 +255,7 @@ class GovspeakTableWithHeadersTest < Minitest::Test
255
255
  assert_equal document_body_with_hashes_for_row_headers.to_html, expected_outcome
256
256
  end
257
257
 
258
- test "Cells are aligned correctly" do
258
+ test "Cells are given classes to indicate alignment" do
259
259
  assert_equal document_body_with_alignments.to_html, expected_outcome_for_table_with_alignments
260
260
  end
261
261
 
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: 7.0.2
4
+ version: 7.1.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: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '23'
53
+ version: '35.1'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '23'
60
+ version: '35.1'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: htmlentities
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -190,14 +190,14 @@ dependencies:
190
190
  requirements:
191
191
  - - '='
192
192
  - !ruby/object:Gem::Version
193
- version: 4.9.0
193
+ version: 4.10.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.9.0
200
+ version: 4.10.0
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: simplecov
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -320,36 +320,36 @@ required_ruby_version: !ruby/object:Gem::Requirement
320
320
  requirements:
321
321
  - - ">="
322
322
  - !ruby/object:Gem::Version
323
- version: '2.7'
323
+ version: '3.0'
324
324
  required_rubygems_version: !ruby/object:Gem::Requirement
325
325
  requirements:
326
326
  - - ">="
327
327
  - !ruby/object:Gem::Version
328
328
  version: '0'
329
329
  requirements: []
330
- rubygems_version: 3.4.2
330
+ rubygems_version: 3.4.13
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Markup language for single domain
334
334
  test_files:
335
335
  - test/blockquote_extra_quote_remover_test.rb
336
336
  - test/govspeak_attachment_link_test.rb
337
- - test/govspeak_images_test.rb
338
- - test/test_helper.rb
339
- - test/govspeak_footnote_test.rb
337
+ - test/govspeak_attachment_test.rb
338
+ - test/govspeak_attachments_image_test.rb
339
+ - test/govspeak_attachments_inline_test.rb
340
340
  - test/govspeak_button_test.rb
341
+ - test/govspeak_contacts_test.rb
342
+ - test/govspeak_extract_contact_content_ids_test.rb
343
+ - test/govspeak_footnote_test.rb
344
+ - test/govspeak_images_bang_test.rb
345
+ - test/govspeak_images_test.rb
346
+ - test/govspeak_link_extractor_test.rb
341
347
  - test/govspeak_link_test.rb
342
- - test/html_sanitizer_test.rb
343
- - test/govspeak_test.rb
348
+ - test/govspeak_structured_headers_test.rb
344
349
  - test/govspeak_table_with_headers_test.rb
350
+ - test/govspeak_test.rb
351
+ - test/govspeak_test_helper.rb
352
+ - test/html_sanitizer_test.rb
345
353
  - test/html_validator_test.rb
346
- - test/govspeak_attachments_image_test.rb
347
- - test/govspeak_images_bang_test.rb
348
- - test/govspeak_link_extractor_test.rb
349
354
  - test/presenters/h_card_presenter_test.rb
350
- - test/govspeak_test_helper.rb
351
- - test/govspeak_attachment_test.rb
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
355
+ - test/test_helper.rb