govspeak 7.1.0 → 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: d3ea39476d15515cff8cf40fa41951ed6d551a495e6f8a40415fdb4eb7752660
4
- data.tar.gz: e084cd737b290c2254fd43796ea4c0a99b906790034a22f258d509a556a726a8
3
+ metadata.gz: 8b23cb6b80ef9b9d71a55b5cf0c1ffa1d33c3127ebac6290e7ed57de253439bd
4
+ data.tar.gz: 5bbe38f1188c1159d7af520b22dc2fc011e95256c53be222170081220c11fa64
5
5
  SHA512:
6
- metadata.gz: c732aaee36be6d012574e52e6d7dc07a906a539f19e9e5d6f4bbf793a7936761fdc5f5c1e8cade26da7ed93830044017fea897ef7890a1d226796407166e372a
7
- data.tar.gz: b7c8a84a1baa01b04483674f10708dd96467b343560dd3c1465de7a0846870ab7a99a6a63da892b48399e4d9cb30f7f18f28273d1a7ad85d433a8a9b79a49fac
6
+ metadata.gz: 13e3cbc3237ad2b739ff8d984d35e040e1379e716791fb9ed7d789b4d4ca9ce6398a53cb8bf095df68af80257aa5d1e2659803857f88677073576685da65df60
7
+ data.tar.gz: 0f9dc64d2983ffa7c546d54f96c852500d92b2b01e2b48d163784b5d41a2a6e38202d8385665c264287b8035d0b8d96059a5fd0be7f065774d602b3caeefc84b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 7.1.1
2
+
3
+ * Make image and attachment embedding syntax more consistent [#274](https://github.com/alphagov/govspeak/pull/274)
4
+
1
5
  ## 7.1.0
2
6
 
3
7
  * Drop support for Ruby 2.7 [#272](https://github.com/alphagov/govspeak/pull/272)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "7.1.0".freeze
2
+ VERSION = "7.1.1".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -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
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.1.0
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-03-28 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
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  - !ruby/object:Gem::Version
328
328
  version: '0'
329
329
  requirements: []
330
- rubygems_version: 3.4.10
330
+ rubygems_version: 3.4.13
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Markup language for single domain