content_block_tools 0.12.0 → 0.12.2

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: 7bd3435567461a7899094649b4c46efc6ae674c943e94b7f7d8dc28615c90c54
4
- data.tar.gz: 9cb772f8e04c00854c6824628f3defa875faa997a85f3c7be458fe1e22c758ee
3
+ metadata.gz: 2a3d284308ecfac92b7c39739db61d4897edd0c185087aa5a307be162e663cc0
4
+ data.tar.gz: 276d0984c5e5c15b2cebcd1a8cf1beb8ad1a92571ab5b087917ad1fb65e90851
5
5
  SHA512:
6
- metadata.gz: 57b390d576c0b7b4d2ac7e16d852d60c97ea3990f69861d633d8cf0041751391c0c8c4b06bd6ae037f057f8b909944a7a48819b75d22e147e497e8b3a0b2f1cc
7
- data.tar.gz: a1d49cbc4e5ad8b87c16e4705d1c68ae7cc3143b960a5c02a9426a1b799a25934cfbdd0670b4605cc43333461b1b203bc4c29a0b8754a5c2126c6423bb6e1dc4
6
+ metadata.gz: 866336c803901cad6a3328343db12db865ba2e256802702f85364fa66f589747a62dee09af69dd34af8969ee381c44cb5b933c0774bba29f2c84a55eb1f01161
7
+ data.tar.gz: d2db11eebab075a70f9b688954cb1b341317284100470fefaf9a7e746ae0c80d69342c307208a089903e3c588974a6bae5630e469458cc7ea2c92a16e9e5b6ae
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.12.2
11
+
12
+ - Add escape character to silence warnings ([65](https://github.com/alphagov/govuk_content_block_tools/pull/65))
13
+
14
+ ## 0.12.1
15
+
16
+ - Fix when content block codes include special dashes ([64](https://github.com/alphagov/govuk_content_block_tools/pull/64))
17
+
10
18
  ## 0.12.0
11
19
 
12
20
  - Add missing fields for contact object ([62](https://github.com/alphagov/govuk_content_block_tools/pull/62))
@@ -32,9 +32,9 @@ module ContentBlockTools
32
32
  # The regex used to find UUIDs
33
33
  UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
34
34
  # The regex used to find content ID aliases
35
- CONTENT_ID_ALIAS_REGEX = /[a-z0-9-]+/
35
+ CONTENT_ID_ALIAS_REGEX = /[a-z0-9\-–—]+/
36
36
  # The regex to find optional field names after the UUID, begins with '/'
37
- FIELD_REGEX = /(\/[a-z0-9_\-\/]*)?/
37
+ FIELD_REGEX = /(\/[a-z0-9_\-–—\/]*)?/
38
38
  # The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document}
39
39
  EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):(#{UUID_REGEX}|#{CONTENT_ID_ALIAS_REGEX})#{FIELD_REGEX}}})/
40
40
 
@@ -52,10 +52,30 @@ module ContentBlockTools
52
52
  # @return [Array<ContentBlockReference>] An array of content block references
53
53
  def find_all_in_document(document)
54
54
  document.scan(ContentBlockReference::EMBED_REGEX).map do |match|
55
+ match = prepare_match(match)
55
56
  ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
56
57
  ContentBlockReference.new(document_type: match[1], identifier: match[2], embed_code: match[0])
57
58
  end
58
59
  end
60
+
61
+ private
62
+
63
+ # This replaces an en / em dashes in content block references with double or triple dashes. This can occur
64
+ # because Kramdown (the markdown parser that Govspeak is based on) replaces double dashes with en dashes and
65
+ # triple dashes with em dashes
66
+ def prepare_match(match)
67
+ [
68
+ replace_dashes(match[0]),
69
+ match[1],
70
+ replace_dashes(match[2]),
71
+ match[3],
72
+ ]
73
+ end
74
+
75
+ def replace_dashes(value)
76
+ value&.gsub("–", "--")
77
+ &.gsub("—", "---")
78
+ end
59
79
  end
60
80
  end
61
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "0.12.0"
4
+ VERSION = "0.12.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_block_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.7.0
153
+ rubygems_version: 3.7.1
154
154
  specification_version: 4
155
155
  summary: A suite of tools for working with GOV.UK Content Blocks
156
156
  test_files: []