content_block_tools 0.12.0 → 0.12.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: 7bd3435567461a7899094649b4c46efc6ae674c943e94b7f7d8dc28615c90c54
4
- data.tar.gz: 9cb772f8e04c00854c6824628f3defa875faa997a85f3c7be458fe1e22c758ee
3
+ metadata.gz: d0c58a0d3ef7154dbb64562eb49e195b35d092aa8253ae4a78281ac82969a0d2
4
+ data.tar.gz: b30e824dc93f731ce4f76feb81d4893405214c735c1c54988ddf45f3f6c7a20d
5
5
  SHA512:
6
- metadata.gz: 57b390d576c0b7b4d2ac7e16d852d60c97ea3990f69861d633d8cf0041751391c0c8c4b06bd6ae037f057f8b909944a7a48819b75d22e147e497e8b3a0b2f1cc
7
- data.tar.gz: a1d49cbc4e5ad8b87c16e4705d1c68ae7cc3143b960a5c02a9426a1b799a25934cfbdd0670b4605cc43333461b1b203bc4c29a0b8754a5c2126c6423bb6e1dc4
6
+ metadata.gz: d7cb23a7de08bd50f54066cccd6e2d3869030745e896d62e8f4d6b8aa48886971a1c313d7328de45d42457250752af7fd018049feda48f4c315d943867423b69
7
+ data.tar.gz: 63ac67b402438f97f09655c96be96a561e5e59c566a19ead87e8c42e55365fec94b5e8ddbefb368d3e10e68d63c271104acaf50a55de98cb96992a73ca959ff8
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.12.1
11
+
12
+ - Fix when content block codes include special dashes ([64](https://github.com/alphagov/govuk_content_block_tools/pull/64))
13
+
10
14
  ## 0.12.0
11
15
 
12
16
  - 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.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev