govuk_publishing_components 39.2.0 → 39.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,7 +42,7 @@
42
42
  <% contents.each.with_index(1) do |contents_item, position| %>
43
43
  <li class="<%= cl_helper.list_item_classes(contents_item, false) %>" <%= "aria-current=true" if contents_item[:active] %>>
44
44
  <span aria-hidden="true"></span>
45
- <% link_text = format_numbers ? cl_helper.wrap_numbers_with_spans(contents_item[:text]) : contents_item[:text]
45
+ <% link_text = format_numbers ? cl_helper.wrap_numbers_with_spans(contents_item[:text]) : cl_helper.clean_string(contents_item[:text])
46
46
  unless disable_ga4
47
47
  ga4_data[:event_name] = cl_helper.get_ga4_event_name(contents_item[:href]) if contents_item[:href]
48
48
  ga4_data[:index_link] = index_link
@@ -88,7 +88,7 @@ examples:
88
88
  format_numbers: true
89
89
  contents:
90
90
  - href: "#first-thing"
91
- text: 1. First thing
91
+ text: 1.&nbsp;First thing
92
92
  - href: "#two"
93
93
  active: true
94
94
  text: 2. Second thing
@@ -22,24 +22,31 @@ module GovukPublishingComponents
22
22
  list_item_classes
23
23
  end
24
24
 
25
- def wrap_numbers_with_spans(content_item_link)
26
- content_item_text = strip_tags(content_item_link) # just the text of the link
27
- content_item_text_stripped = content_item_text.strip # strip trailing spaces for the regex. Keep original content_item_text for the string replacement.
25
+ def wrap_numbers_with_spans(link_text)
26
+ output = clean_string(link_text)
28
27
  # Must start with a number
29
28
  # Number must be between 1 and 999 (ie not 2014)
30
29
  # Must be followed by a space
31
30
  # May contain a period `1.`
32
31
  # May be a decimal `1.2`
33
- number = /^\d{1,3}(\.?|\.\d{1,2})(?=\s)/.match(content_item_text_stripped)
32
+ number = /^\d{1,3}(\.?|\.\d{1,2})(?=\s)/.match(output)
34
33
 
35
34
  if number
36
- words = content_item_text.sub(number.to_s, "").strip # remove the number from the text
37
- content_item_link.sub(content_item_text, "<span class=\"gem-c-contents-list__number\">#{number} </span><span class=\"gem-c-contents-list__numbered-text\">#{words}</span>").squish.html_safe
35
+ words = output.sub(number.to_s, "").strip # remove the number from the text
36
+ # the space in the first span is needed for screen readers
37
+ "<span class=\"gem-c-contents-list__number\">#{number} </span><span class=\"gem-c-contents-list__numbered-text\">#{words}</span>".squish.html_safe
38
38
  else
39
- content_item_link
39
+ output
40
40
  end
41
41
  end
42
42
 
43
+ def clean_string(text)
44
+ text = text.gsub(/&nbsp;/, " ")
45
+ text = text.gsub("/\u00a0/", " ")
46
+ text = text.gsub(160.chr("UTF-8"), " ")
47
+ strip_tags(text.tr("\n", "")).strip
48
+ end
49
+
43
50
  def get_index_total
44
51
  total = @contents.length
45
52
  @contents.each do |parent|
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "39.2.0".freeze
2
+ VERSION = "39.2.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 39.2.0
4
+ version: 39.2.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: 2024-07-01 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config