govspeak 5.9.0 → 5.9.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: aefa5ca742f032b154510d7a90ca70e4cb26adb803811ed4aac9377d07ea21ff
4
- data.tar.gz: 6fdb391bb18c3b90c07f5d52a75758edc82711848da11578aab725eae6b556d7
3
+ metadata.gz: a66dce46f2af9208dfc78c813b601fe8a447a0c5a68c085516dcf37d9fd5567d
4
+ data.tar.gz: 62323ec0ee81856973bea87d1575a5aac0d1c4f957ad2261d3081ec6206a45f9
5
5
  SHA512:
6
- metadata.gz: 2af64448e8f05a2e7aff9da5f81e252ff4ad5d466b8c9e7eba24114f937993f99ba0e8e59b1481c6fb1dba6dd6b438ec28e5735380b3d4879355a8eba20d4809
7
- data.tar.gz: f4a4dbb952b94c994c8697d52b8a905bf457a98883ef8d23a8f661528f719632f28acb0c1cbcc1e7a26195340dafce0e2e7bac950f8e89eb0e4f675fea7af291
6
+ metadata.gz: 4b14f7a1707a14e6342b709425556c5d69f64c12ba6523fc0c30ad5a8a98580e05115842cb7c70aa949c219683901e050c415df7b63249c910c59c73a75e011c
7
+ data.tar.gz: '02386b5204b077af3a5fa03512e0ed451b77ec3a65e38b17015bab5267431b25382b0103338128c02583e6a3b075eb6ff7f41210a3bdcb8a236d139d182cd6c6'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 5.9.1
2
+
3
+ * Don't render `[Image: {file-name}]` within a paragraph to avoid invalid HTML
4
+
1
5
  ## 5.9.0
2
6
 
3
7
  * Add image credits to embedded images
data/lib/govspeak.rb CHANGED
@@ -29,6 +29,7 @@ module Govspeak
29
29
  Parser = Kramdown::Parser::KramdownWithAutomaticExternalLinks
30
30
  PARSER_CLASS_NAME = Parser.name.split("::").last
31
31
  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
32
+ NEW_PARAGRAPH_LOOKBEHIND = %q{(?<=\A|\n\n|\r\n\r\n)}.freeze
32
33
 
33
34
  @extensions = []
34
35
 
@@ -287,7 +288,7 @@ module Govspeak
287
288
  %{\n<div class="address"><div class="adr org fn"><p>\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n}
288
289
  }
289
290
 
290
- extension("legislative list", /(?<=\A|\n\n|\r\n\r\n)^\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
291
+ extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
291
292
  Govspeak::KramdownOverrides.with_kramdown_ordered_lists_disabled do
292
293
  Kramdown::Document.new(body.strip).to_html.tap do |doc|
293
294
  doc.gsub!('<ul>', '<ol>')
@@ -324,7 +325,7 @@ module Govspeak
324
325
  end
325
326
  end
326
327
 
327
- extension("Priority list", /(?<=\A|\n\n|\r\n\r\n)^\$PriorityList:(\d+)\s*$(.*?)(?:^\s*$|\Z)/m) do |number_to_show, body|
328
+ extension("Priority list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$PriorityList:(\d+)\s*$(.*?)(?:^\s*$|\Z)/m) do |number_to_show, body|
328
329
  number_to_show = number_to_show.to_i
329
330
  tagged = 0
330
331
  Govspeak::Document.new(body.strip).to_html.gsub(/<li>/) do |match|
@@ -357,7 +358,7 @@ module Govspeak
357
358
  @renderer.result(binding)
358
359
  end
359
360
 
360
- extension('Image', /\[Image:\s*(.*?)\s*\]/) do |image_id|
361
+ extension('Image', /#{NEW_PARAGRAPH_LOOKBEHIND}\[Image:\s*(.*?)\s*\]/) do |image_id|
361
362
  image = images.detect { |c| c.is_a?(Hash) && c[:id] == image_id }
362
363
  next "" unless image
363
364
 
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "5.9.0".freeze
2
+ VERSION = "5.9.1".freeze
3
3
  end
@@ -93,4 +93,27 @@ class GovspeakImagesTest < Minitest::Test
93
93
  )
94
94
  end
95
95
  end
96
+
97
+ test "Image is not inserted when it does not start on a new line" do
98
+ given_govspeak "some text [Image:image-id]", images: [build_image] do
99
+ assert_html_output("<p>some text [Image:image-id]</p>")
100
+ end
101
+
102
+ given_govspeak "[Image:image-id]", images: [build_image] do
103
+ assert_html_output(
104
+ %{<figure class="image embedded">} +
105
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
106
+ %{</figure>}
107
+ )
108
+ end
109
+
110
+ given_govspeak "[Image:image-id] some text", images: [build_image] do
111
+ assert_html_output(
112
+ %{<figure class="image embedded">} +
113
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
114
+ %{</figure>\n} +
115
+ %{<p>some text</p>}
116
+ )
117
+ end
118
+ end
96
119
  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: 5.9.0
4
+ version: 5.9.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: 2018-12-21 00:00:00.000000000 Z
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -359,27 +359,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
359
359
  - !ruby/object:Gem::Version
360
360
  version: '0'
361
361
  requirements: []
362
- rubyforge_project:
363
- rubygems_version: 2.7.6
362
+ rubygems_version: 3.0.1
364
363
  signing_key:
365
364
  specification_version: 4
366
365
  summary: Markup language for single domain
367
366
  test_files:
368
- - test/blockquote_extra_quote_remover_test.rb
369
- - test/govspeak_test_helper.rb
367
+ - test/govspeak_link_extractor_test.rb
370
368
  - test/govspeak_structured_headers_test.rb
371
- - test/govspeak_attachments_image_test.rb
372
- - test/govspeak_attachments_test.rb
373
- - test/test_helper.rb
374
- - test/govspeak_attachments_inline_test.rb
375
- - test/html_sanitizer_test.rb
376
- - test/govspeak_button_test.rb
377
369
  - test/govspeak_images_bang_test.rb
378
- - test/govspeak_images_test.rb
379
- - test/html_validator_test.rb
370
+ - test/govspeak_button_test.rb
380
371
  - test/govspeak_extract_contact_content_ids_test.rb
381
- - test/govspeak_test.rb
382
- - test/govspeak_link_extractor_test.rb
372
+ - test/blockquote_extra_quote_remover_test.rb
373
+ - test/govspeak_test_helper.rb
383
374
  - test/govspeak_link_test.rb
375
+ - test/govspeak_images_test.rb
384
376
  - test/govspeak_contacts_test.rb
377
+ - test/test_helper.rb
378
+ - test/html_validator_test.rb
379
+ - test/html_sanitizer_test.rb
380
+ - test/govspeak_attachments_inline_test.rb
381
+ - test/govspeak_test.rb
382
+ - test/govspeak_attachments_test.rb
383
+ - test/govspeak_attachments_image_test.rb
385
384
  - test/presenters/h_card_presenter_test.rb