govspeak 10.7.0 → 10.8.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +30 -2
- data/lib/govspeak/post_processor.rb +3 -1
- data/lib/govspeak/structured_header_extractor.rb +4 -4
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +4 -4
- data/test/govspeak_structured_headers_test.rb +21 -0
- data/test/govspeak_test.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 733f9a53a5ef973b6a5342613ba74a3511ffd72e35c90d03e6aafee6179812cf
|
|
4
|
+
data.tar.gz: b79467615c87b31c19448b30a95d8abf9cef2392afa756b9844aac539ce41f24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 582e8c1dc672de89f3dd8baa795df2d6ff90646b313cca6ec71cd6d63d0a3b506e2b1aef8e8ed7d729195557496d934a98b810249111eb2690eafe68c322c8c8
|
|
7
|
+
data.tar.gz: fd31d88a87ab6b5148666387230d83b36af33bf74d6270fe65c6a7ff5f5d555820364fec601c04ec3298ab2fc5f5f4b5f26d4ea7bec53445e49b09ce2067b217
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 10.8.1
|
|
4
|
+
|
|
5
|
+
* fix: Ensure i18n load paths are flattened [PR #453](https://github.com/alphagov/govspeak/pull/453)
|
|
6
|
+
|
|
7
|
+
## 10.8.0
|
|
8
|
+
|
|
9
|
+
* feature: Allow callers to specify which headers will be auto-numbered [PR #451](https://github.com/alphagov/govspeak/pull/451)
|
|
10
|
+
|
|
3
11
|
## 10.7.0
|
|
4
12
|
|
|
5
13
|
* feature: Add auto-numbered headers option [PR #449](https://github.com/alphagov/govspeak/pull/449)
|
data/README.md
CHANGED
|
@@ -22,7 +22,7 @@ then create a new document
|
|
|
22
22
|
|
|
23
23
|
Some additional steps or considerations are needed to ensure changes to govspeak cascade across GOV.UK in a holistic way.
|
|
24
24
|
|
|
25
|
-
Once govspeak has been updated and version incremented then:
|
|
25
|
+
Once govspeak has been updated and version incremented then:
|
|
26
26
|
- [`govuk_publishing_components` govspeak](https://components.publishing.service.gov.uk/component-guide/govspeak) will also need updating to reflect your most recent change.
|
|
27
27
|
- [Publishing apps](https://docs.publishing.service.gov.uk/apps.html) (including but not limited to [content-publisher](https://github.com/alphagov/content-publisher) & [whitehall](https://github.com/alphagov/whitehall)) also use govspeak, these apps will need to be released with the new govspeak version present.
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ Also, consider if:
|
|
|
30
30
|
- [whitehall](https://github.com/alphagov/whitehall) needs updating (as custom govspeak changes are present)
|
|
31
31
|
- [govspeak-preview](https://github.com/alphagov/govspeak-preview) needs updating
|
|
32
32
|
|
|
33
|
-
Any pages that use govspeak to generate Content will need to *republished* in order for the new changes to be reflected.
|
|
33
|
+
Any pages that use govspeak to generate Content will need to be *republished* in order for the new changes to be reflected.
|
|
34
34
|
|
|
35
35
|
- Data Labs can help identify which pages need updating by [submitting a request](https://gov-uk.atlassian.net/wiki/spaces/GOVUK/pages/1860075525/GOV.UK+Data+Labs#Submitting-a-data-science-request) and [#govuk-2ndline](https://docs.publishing.service.gov.uk/manual/2nd-line.html) can help with republishing
|
|
36
36
|
|
|
@@ -48,6 +48,34 @@ with understanding how the content transforms from source through:
|
|
|
48
48
|
|
|
49
49
|
In addition to the [standard Markdown syntax](http://daringfireball.net/projects/markdown/syntax "Markdown syntax"), we have added our own extensions.
|
|
50
50
|
|
|
51
|
+
## Autonumbered headers
|
|
52
|
+
|
|
53
|
+
This extension is off by default, can be turned on with
|
|
54
|
+
|
|
55
|
+
doc = Govspeak::Document.new "## Header\n### Sub-header\n#### Sub-sub-header", auto_numbered_headers: true
|
|
56
|
+
|
|
57
|
+
Creates automatically numbered headers
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<h2>1 Header</h2>
|
|
61
|
+
<h3>1.1 Sub-header</h3>
|
|
62
|
+
<h4>1.1.1 Sub-sub-header</h4>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
By default the numbering scheme will work for all headers apart from H1s, if you want to
|
|
66
|
+
restrict this you can specify the levels you want in an array (default value is [2,3,4,5,6])
|
|
67
|
+
|
|
68
|
+
doc = Govspeak::Document.new "## Header\n### Sub-header\n#### Sub-sub-header", auto_numbered_headers: true, auto_numbered_header_levels: [2,3]
|
|
69
|
+
|
|
70
|
+
Creates automatically numbered headers
|
|
71
|
+
|
|
72
|
+
```html
|
|
73
|
+
<h2>1 Header</h2>
|
|
74
|
+
<h3>1.1 Sub-header</h3>
|
|
75
|
+
<h4>Sub-sub-header</h4>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
|
|
51
79
|
## Callouts
|
|
52
80
|
|
|
53
81
|
### Information callouts
|
|
@@ -164,7 +164,9 @@ module Govspeak
|
|
|
164
164
|
if govspeak_document.auto_numbered_headers
|
|
165
165
|
h2, h3, h4, h5, h6 = 0, 0, 0, 0, 0, 0
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
selector = govspeak_document.auto_numbered_header_levels.map { |i| "h#{i}" }.join(",")
|
|
168
|
+
|
|
169
|
+
document.css(selector).map do |el|
|
|
168
170
|
case el.name
|
|
169
171
|
when "h2"
|
|
170
172
|
h2 += 1
|
|
@@ -41,7 +41,7 @@ module Govspeak
|
|
|
41
41
|
stack.push(header)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
add_auto_numbering(structured_headers) if doc.auto_numbered_headers
|
|
44
|
+
add_auto_numbering(structured_headers, doc.auto_numbered_header_levels) if doc.auto_numbered_headers
|
|
45
45
|
|
|
46
46
|
structured_headers
|
|
47
47
|
end
|
|
@@ -98,10 +98,10 @@ module Govspeak
|
|
|
98
98
|
@stack = []
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
def add_auto_numbering(structured_headers, prefix: "")
|
|
101
|
+
def add_auto_numbering(structured_headers, levels, prefix: "")
|
|
102
102
|
structured_headers.each.with_index(1) do |header, index|
|
|
103
|
-
header[:text] = "#{prefix}#{index}#{'.' if prefix == ''} #{header[:text]}"
|
|
104
|
-
add_auto_numbering(header[:headers], prefix: "#{prefix}#{index}.")
|
|
103
|
+
header[:text] = "#{prefix}#{index}#{'.' if prefix == ''} #{header[:text]}" if levels.include?(header[:level])
|
|
104
|
+
add_auto_numbering(header[:headers], levels, prefix: "#{prefix}#{index}.")
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
|
@@ -38,7 +38,7 @@ module Govspeak
|
|
|
38
38
|
@extensions = []
|
|
39
39
|
|
|
40
40
|
attr_accessor :images
|
|
41
|
-
attr_reader :attachments, :auto_numbered_headers, :contacts, :links, :locale, :log_snapshots
|
|
41
|
+
attr_reader :attachments, :auto_numbered_headers, :auto_numbered_header_levels, :contacts, :links, :locale, :log_snapshots
|
|
42
42
|
|
|
43
43
|
def self.to_html(source, options = {})
|
|
44
44
|
new(source, options).to_html
|
|
@@ -55,12 +55,12 @@ module Govspeak
|
|
|
55
55
|
@log_snapshots = options.fetch(:log_snapshots, false)
|
|
56
56
|
log_snapshot("options", options)
|
|
57
57
|
log_snapshot("source", @source)
|
|
58
|
-
|
|
59
58
|
@images = options.delete(:images) || []
|
|
60
59
|
@allowed_elements = options.delete(:allowed_elements) || []
|
|
61
60
|
@allowed_image_hosts = options.delete(:allowed_image_hosts) || []
|
|
62
61
|
@attachments = Array.wrap(options.delete(:attachments))
|
|
63
62
|
@auto_numbered_headers = options.fetch(:auto_numbered_headers, false)
|
|
63
|
+
@auto_numbered_header_levels = options.delete(:auto_numbered_header_levels) || [2, 3, 4, 5, 6]
|
|
64
64
|
@links = Array.wrap(options.delete(:links))
|
|
65
65
|
@contacts = Array.wrap(options.delete(:contacts))
|
|
66
66
|
@locale = options.fetch(:locale, "en")
|
|
@@ -439,9 +439,9 @@ module Govspeak
|
|
|
439
439
|
end
|
|
440
440
|
end
|
|
441
441
|
|
|
442
|
-
locale_paths =
|
|
442
|
+
locale_paths = Dir.glob(File.expand_path("locales/*.yml", Govspeak.root))
|
|
443
443
|
|
|
444
|
-
I18n.load_path.unshift(locale_paths)
|
|
444
|
+
I18n.load_path.unshift(*locale_paths)
|
|
445
445
|
I18n.available_locales = locale_paths.map do |path|
|
|
446
446
|
path.match(/([^\/]+).yml/)[1].to_sym
|
|
447
447
|
end
|
|
@@ -166,4 +166,25 @@ class GovspeakStructuredHeadersTest < Minitest::Test
|
|
|
166
166
|
assert_equal "5. Heading 5", headers[4][:text]
|
|
167
167
|
assert_equal "5.1 Sub heading 5.1", headers[4][:headers][0][:text]
|
|
168
168
|
end
|
|
169
|
+
|
|
170
|
+
test "auto-numbered headers are restricted to appropriate levels when the option is set on the document" do
|
|
171
|
+
doc = Govspeak::Document.new(document_body, auto_numbered_headers: true, auto_numbered_header_levels: [2, 3])
|
|
172
|
+
|
|
173
|
+
headers = doc.structured_headers
|
|
174
|
+
|
|
175
|
+
assert_equal "1. Heading 1", headers[0][:text]
|
|
176
|
+
assert_equal "2. Heading 2", headers[1][:text]
|
|
177
|
+
assert_equal "2.1 Sub heading 2.1", headers[1][:headers][0][:text]
|
|
178
|
+
assert_equal "2.2 Sub heading 2.2", headers[1][:headers][1][:text]
|
|
179
|
+
assert_equal "Sub sub heading 2.2.1", headers[1][:headers][1][:headers][0][:text]
|
|
180
|
+
assert_equal "2.3 Sub heading 2.3", headers[1][:headers][2][:text]
|
|
181
|
+
assert_equal "3. Heading 3", headers[2][:text]
|
|
182
|
+
assert_equal "4. Heading 4", headers[3][:text]
|
|
183
|
+
assert_equal "4.1 Sub heading 4.1", headers[3][:headers][0][:text]
|
|
184
|
+
assert_equal "Sub sub heading 4.1.1", headers[3][:headers][0][:headers][0][:text]
|
|
185
|
+
assert_equal "Sub sub sub heading 4.1.1.1", headers[3][:headers][0][:headers][0][:headers][0][:text]
|
|
186
|
+
assert_equal "4.2 Sub heading 4.2", headers[3][:headers][1][:text]
|
|
187
|
+
assert_equal "5. Heading 5", headers[4][:text]
|
|
188
|
+
assert_equal "5.1 Sub heading 5.1", headers[4][:headers][0][:text]
|
|
189
|
+
end
|
|
169
190
|
end
|
data/test/govspeak_test.rb
CHANGED
|
@@ -121,6 +121,28 @@ class GovspeakTest < Minitest::Test
|
|
|
121
121
|
assert_equal %(\n<h2 id="h2-one">1. H2 One</h2>\n\n<h3 id="h3-one">1.1 H3 One</h3>\n\n<h3 id="h3-two">1.2 H3 Two</h3>\n\n<h2 id="h2-two">2. H2 Two</h2>\n\n<h3 id="h3-three">2.1 H3 Three</h3>\n\n<h4 id="h4-one">2.1.1 H4 One</h4>\n\n<h5 id="h5-one">2.1.1.1 H5 One</h5>\n\n<h6 id="h6-one">2.1.1.1.1 H6 One</h6>\n), doc.to_html
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
+
test "restricts auto-numbered headings to specified levels when the auto_numbered_heading_levels option is set" do
|
|
125
|
+
input = %(
|
|
126
|
+
## H2 One
|
|
127
|
+
|
|
128
|
+
### H3 One
|
|
129
|
+
|
|
130
|
+
### H3 Two
|
|
131
|
+
|
|
132
|
+
## H2 Two
|
|
133
|
+
|
|
134
|
+
### H3 Three
|
|
135
|
+
|
|
136
|
+
#### H4 One
|
|
137
|
+
|
|
138
|
+
##### H5 One
|
|
139
|
+
|
|
140
|
+
###### H6 One
|
|
141
|
+
)
|
|
142
|
+
doc = Govspeak::Document.new(input, auto_numbered_headers: true, auto_numbered_header_levels: [2, 3])
|
|
143
|
+
assert_equal %(\n<h2 id="h2-one">1. H2 One</h2>\n\n<h3 id="h3-one">1.1 H3 One</h3>\n\n<h3 id="h3-two">1.2 H3 Two</h3>\n\n<h2 id="h2-two">2. H2 Two</h2>\n\n<h3 id="h3-three">2.1 H3 Three</h3>\n\n<h4 id="h4-one">H4 One</h4>\n\n<h5 id="h5-one">H5 One</h5>\n\n<h6 id="h6-one">H6 One</h6>\n), doc.to_html
|
|
144
|
+
end
|
|
145
|
+
|
|
124
146
|
test "trailing space after the address should not prevent parsing" do
|
|
125
147
|
input = %($A
|
|
126
148
|
123 Test Street
|
|
@@ -1579,4 +1601,8 @@ Or so we thought.)
|
|
|
1579
1601
|
)
|
|
1580
1602
|
end
|
|
1581
1603
|
end
|
|
1604
|
+
|
|
1605
|
+
test "I18n load_path is not set as a nested array" do
|
|
1606
|
+
assert_equal I18n.load_path.count, I18n.load_path.flatten.count
|
|
1607
|
+
end
|
|
1582
1608
|
end
|