govspeak 10.3.0 → 10.4.0
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 +4 -0
- data/README.md +11 -1
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +24 -5
- data/test/govspeak_informational_test.rb +100 -0
- data/test/govspeak_test.rb +0 -26
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a3bf8e18b1cfd9bb3c71bf3774e9232c0c3defa120fd60f983fa9acf47c0b51
|
4
|
+
data.tar.gz: 813f4543fa558f0394e29f06afcc52b6e95ed10714b25ae02607c7f185f78a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa85cc0a63094caaf65aef58851ece00cf9dd3cf32d2ff8c876758a07fb7d139ac7dc19a9b3446b73b8d31a8bef137c4b3b0e41ba1079223c4530fe95e212cf
|
7
|
+
data.tar.gz: ccaa75526e6f9e947f1a2409156a60ca16d904b29c1a877ce8b84264ea2c655dd2a6991c2b992608d992ee26bb0ceb2189e1bc6b12f698091b9956b154f1ac25
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -33,7 +33,17 @@ Also, consider if:
|
|
33
33
|
Any pages that use govspeak to generate Content will need to *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
|
+
|
37
|
+
## Debugging
|
38
|
+
|
39
|
+
If `log_snapshots: true` is provided as an option when initialising a
|
40
|
+
`Govspeak::Document`, a few useful snapshots will be provided. This can help
|
41
|
+
with understanding how the content transforms from source through:
|
42
|
+
|
43
|
+
- preprocessing (our main Govspeak rendering point);
|
44
|
+
- Kramdown processing (the Markdown rendering point); and
|
45
|
+
- postprocessing (an additional Govspeak rendering point).
|
46
|
+
|
37
47
|
# Extensions
|
38
48
|
|
39
49
|
In addition to the [standard Markdown syntax](http://daringfireball.net/projects/markdown/syntax "Markdown syntax"), we have added our own extensions.
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -37,7 +37,7 @@ module Govspeak
|
|
37
37
|
@extensions = []
|
38
38
|
|
39
39
|
attr_accessor :images
|
40
|
-
attr_reader :attachments, :contacts, :links, :locale
|
40
|
+
attr_reader :attachments, :contacts, :links, :locale, :log_snapshots
|
41
41
|
|
42
42
|
def self.to_html(source, options = {})
|
43
43
|
new(source, options).to_html
|
@@ -51,6 +51,10 @@ module Govspeak
|
|
51
51
|
options = options.dup.deep_symbolize_keys
|
52
52
|
@source = source ? source.dup : ""
|
53
53
|
|
54
|
+
@log_snapshots = options.fetch(:log_snapshots, false)
|
55
|
+
log_snapshot("options", options)
|
56
|
+
log_snapshot("source", @source)
|
57
|
+
|
54
58
|
@images = options.delete(:images) || []
|
55
59
|
@allowed_elements = options.delete(:allowed_elements) || []
|
56
60
|
@allowed_image_hosts = options.delete(:allowed_image_hosts) || []
|
@@ -73,7 +77,11 @@ module Govspeak
|
|
73
77
|
kramdown_doc.to_html
|
74
78
|
end
|
75
79
|
|
76
|
-
|
80
|
+
log_snapshot("after Kramdown process", html)
|
81
|
+
|
82
|
+
Govspeak::PostProcessor.process(html, self).tap do
|
83
|
+
log_snapshot("after postprocess", _1)
|
84
|
+
end
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
@@ -117,7 +125,8 @@ module Govspeak
|
|
117
125
|
instance_exec(*Regexp.last_match.captures, &block)
|
118
126
|
end
|
119
127
|
end
|
120
|
-
|
128
|
+
|
129
|
+
source.tap { log_snapshot("after preprocess", _1) }
|
121
130
|
end
|
122
131
|
|
123
132
|
def remove_forbidden_characters(source)
|
@@ -197,8 +206,11 @@ module Govspeak
|
|
197
206
|
end
|
198
207
|
|
199
208
|
extension("informational", surrounded_by("^")) do |body|
|
200
|
-
|
201
|
-
|
209
|
+
<<~BODY
|
210
|
+
\n\n<div role="note" aria-label="Information" class="application-notice info-notice" markdown="1">
|
211
|
+
#{body.strip}
|
212
|
+
</div>
|
213
|
+
BODY
|
202
214
|
end
|
203
215
|
|
204
216
|
extension("helpful", surrounded_by("%")) do |body|
|
@@ -390,6 +402,13 @@ module Govspeak
|
|
390
402
|
|
391
403
|
private
|
392
404
|
|
405
|
+
def log_snapshot(description, *objects)
|
406
|
+
return unless log_snapshots
|
407
|
+
|
408
|
+
puts "===== #{description} ====="
|
409
|
+
!objects.empty? && objects.each { puts _1 }
|
410
|
+
end
|
411
|
+
|
393
412
|
def kramdown_doc
|
394
413
|
@kramdown_doc ||= Kramdown::Document.new(preprocess(@source), @options)
|
395
414
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "govspeak_test_helper"
|
3
|
+
|
4
|
+
class GovspeakImagesTest < Minitest::Test
|
5
|
+
include GovspeakTestHelper
|
6
|
+
extend Minitest::Spec::DSL
|
7
|
+
|
8
|
+
test "renders okay with just an opening tag" do
|
9
|
+
given_govspeak "^ I am very informational" do
|
10
|
+
assert_html_output %(
|
11
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
12
|
+
<p>I am very informational</p>
|
13
|
+
</div>)
|
14
|
+
assert_text_output "I am very informational"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "renders okay with opening and closing tags" do
|
19
|
+
given_govspeak("^ I am very informational ^") do
|
20
|
+
assert_html_output %(
|
21
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
22
|
+
<p>I am very informational</p>
|
23
|
+
</div>)
|
24
|
+
assert_text_output "I am very informational"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "renders okay with no space after the opening tag" do
|
29
|
+
given_govspeak("^I am very informational") do
|
30
|
+
assert_html_output %(
|
31
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
32
|
+
<p>I am very informational</p>
|
33
|
+
</div>)
|
34
|
+
assert_text_output "I am very informational"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "avoids combining into a single block with an immediately-preceding line" do
|
39
|
+
given_govspeak "The following is very informational\n^ I am very informational ^" do
|
40
|
+
assert_html_output %(
|
41
|
+
<p>The following is very informational</p>
|
42
|
+
|
43
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
44
|
+
<p>I am very informational</p>
|
45
|
+
</div>)
|
46
|
+
assert_text_output "The following is very informational I am very informational"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "support for nested Kramdown" do
|
51
|
+
test "supports headings" do
|
52
|
+
given_govspeak "^ ## I am an informational heading" do
|
53
|
+
assert_html_output %(
|
54
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
55
|
+
<h2 id="i-am-an-informational-heading">I am an informational heading</h2>
|
56
|
+
</div>)
|
57
|
+
assert_text_output "I am an informational heading"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
test "supports abbreviations" do
|
62
|
+
given_govspeak "^ I am very informational
|
63
|
+
|
64
|
+
Live, love, informational
|
65
|
+
|
66
|
+
*[informational]: do with it what you will
|
67
|
+
" do
|
68
|
+
assert_html_output %(
|
69
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
70
|
+
<p>I am very <abbr title="do with it what you will">informational</abbr></p>
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<p>Live, love, <abbr title="do with it what you will">informational</abbr></p>)
|
74
|
+
assert_text_output "I am very informational Live, love, informational"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test "supports links" do
|
79
|
+
given_govspeak "^ [My informational link](https://www.gov.uk)" do
|
80
|
+
assert_html_output %(
|
81
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
82
|
+
<p><a href="https://www.gov.uk">My informational link</a></p>
|
83
|
+
</div>
|
84
|
+
)
|
85
|
+
assert_text_output "My informational link"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test "supports bold emphasis" do
|
90
|
+
given_govspeak "^ I am **very** informational" do
|
91
|
+
assert_html_output %(
|
92
|
+
<div role="note" aria-label="Information" class="application-notice info-notice">
|
93
|
+
<p>I am <strong>very</strong> informational</p>
|
94
|
+
</div>
|
95
|
+
)
|
96
|
+
assert_text_output "I am very informational"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/test/govspeak_test.rb
CHANGED
@@ -177,38 +177,12 @@ Teston
|
|
177
177
|
assert_equal %(<p>Paragraph1</p>\n\n<div class="address"><div class="adr org fn"><p>\n123 Test Street<br>Testcase Cliffs<br>Teston<br>0123 456 7890\n</p></div></div>\n), doc.to_html
|
178
178
|
end
|
179
179
|
|
180
|
-
test_given_govspeak("^ I am very informational ^") do
|
181
|
-
assert_html_output %(
|
182
|
-
<div role="note" aria-label="Information" class="application-notice info-notice">
|
183
|
-
<p>I am very informational</p>
|
184
|
-
</div>)
|
185
|
-
assert_text_output "I am very informational"
|
186
|
-
end
|
187
|
-
|
188
180
|
test "processing an extension does not modify the provided input" do
|
189
181
|
input = "^ I am very informational"
|
190
182
|
Govspeak::Document.new(input).to_html
|
191
183
|
assert_equal "^ I am very informational", input
|
192
184
|
end
|
193
185
|
|
194
|
-
test_given_govspeak "The following is very informational\n^ I am very informational ^" do
|
195
|
-
assert_html_output %(
|
196
|
-
<p>The following is very informational</p>
|
197
|
-
|
198
|
-
<div role="note" aria-label="Information" class="application-notice info-notice">
|
199
|
-
<p>I am very informational</p>
|
200
|
-
</div>)
|
201
|
-
assert_text_output "The following is very informational I am very informational"
|
202
|
-
end
|
203
|
-
|
204
|
-
test_given_govspeak "^ I am very informational" do
|
205
|
-
assert_html_output %(
|
206
|
-
<div role="note" aria-label="Information" class="application-notice info-notice">
|
207
|
-
<p>I am very informational</p>
|
208
|
-
</div>)
|
209
|
-
assert_text_output "I am very informational"
|
210
|
-
end
|
211
|
-
|
212
186
|
test_given_govspeak "% I am very helpful %" do
|
213
187
|
assert_html_output %(
|
214
188
|
<div role="note" aria-label="Warning" class="application-notice help-notice">
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govspeak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -213,14 +213,14 @@ dependencies:
|
|
213
213
|
requirements:
|
214
214
|
- - '='
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
version: 5.1.
|
216
|
+
version: 5.1.15
|
217
217
|
type: :development
|
218
218
|
prerelease: false
|
219
219
|
version_requirements: !ruby/object:Gem::Requirement
|
220
220
|
requirements:
|
221
221
|
- - '='
|
222
222
|
- !ruby/object:Gem::Version
|
223
|
-
version: 5.1.
|
223
|
+
version: 5.1.15
|
224
224
|
- !ruby/object:Gem::Dependency
|
225
225
|
name: simplecov
|
226
226
|
requirement: !ruby/object:Gem::Requirement
|
@@ -322,6 +322,7 @@ files:
|
|
322
322
|
- test/govspeak_footnote_test.rb
|
323
323
|
- test/govspeak_images_bang_test.rb
|
324
324
|
- test/govspeak_images_test.rb
|
325
|
+
- test/govspeak_informational_test.rb
|
325
326
|
- test/govspeak_link_extractor_test.rb
|
326
327
|
- test/govspeak_link_test.rb
|
327
328
|
- test/govspeak_structured_headers_test.rb
|
@@ -366,6 +367,7 @@ test_files:
|
|
366
367
|
- test/govspeak_footnote_test.rb
|
367
368
|
- test/govspeak_images_bang_test.rb
|
368
369
|
- test/govspeak_images_test.rb
|
370
|
+
- test/govspeak_informational_test.rb
|
369
371
|
- test/govspeak_link_extractor_test.rb
|
370
372
|
- test/govspeak_link_test.rb
|
371
373
|
- test/govspeak_structured_headers_test.rb
|