govspeak 5.6.0 → 5.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/Rakefile +1 -7
- data/bin/govspeak +1 -1
- data/lib/govspeak.rb +76 -55
- data/lib/govspeak/blockquote_extra_quote_remover.rb +3 -2
- data/lib/govspeak/cli.rb +5 -3
- data/lib/govspeak/header_extractor.rb +6 -5
- data/lib/govspeak/html_sanitizer.rb +5 -5
- data/lib/govspeak/kramdown_overrides.rb +1 -2
- data/lib/govspeak/link_extractor.rb +1 -1
- data/lib/govspeak/post_processor.rb +28 -21
- data/lib/govspeak/presenters/attachment_presenter.rb +12 -7
- data/lib/govspeak/presenters/contact_presenter.rb +55 -10
- data/lib/govspeak/presenters/h_card_presenter.rb +22 -32
- data/lib/govspeak/structured_header_extractor.rb +0 -1
- data/lib/govspeak/version.rb +1 -1
- data/lib/kramdown/parser/kramdown_with_automatic_external_links.rb +12 -10
- data/lib/templates/attachment.html.erb +9 -9
- data/lib/templates/contact.html.erb +15 -18
- data/test/govspeak_attachments_test.rb +0 -53
- data/test/govspeak_contacts_test.rb +125 -38
- data/test/govspeak_extract_contact_content_ids_test.rb +29 -0
- data/test/govspeak_link_extractor_test.rb +1 -1
- data/test/govspeak_structured_headers_test.rb +20 -21
- data/test/govspeak_test.rb +41 -40
- data/test/govspeak_test_helper.rb +7 -10
- data/test/html_sanitizer_test.rb +3 -4
- data/test/html_validator_test.rb +7 -7
- data/test/presenters/h_card_presenter_test.rb +11 -13
- data/test/test_helper.rb +6 -5
- metadata +70 -74
@@ -344,59 +344,6 @@ class GovspeakAttachmentTest < Minitest::Test
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
test "a full attachment rendering looks correct" do
|
348
|
-
attachment = {
|
349
|
-
id: 123,
|
350
|
-
content_id: "2b4d92f3-f8cd-4284-aaaa-25b3a640d26c",
|
351
|
-
title: "Attachment Title",
|
352
|
-
url: "http://example.com/test.pdf",
|
353
|
-
opendocument?: true,
|
354
|
-
order_url: "http://example.com/order",
|
355
|
-
price: 12.3,
|
356
|
-
isbn: "isbn-123",
|
357
|
-
unnumbered_command_paper?: true,
|
358
|
-
}
|
359
|
-
rendered = render_govspeak(
|
360
|
-
"[embed:attachments:2b4d92f3-f8cd-4284-aaaa-25b3a640d26c]",
|
361
|
-
[build_attachment(attachment)]
|
362
|
-
)
|
363
|
-
expected_html_output = %{
|
364
|
-
<section class="attachment embedded">
|
365
|
-
<div class="attachment-thumb">
|
366
|
-
<a href="http://example.com/test.pdf" aria-hidden="true" class="embedded"><img src="/images/pub-cover.png" alt="Pub cover"></a>
|
367
|
-
</div>
|
368
|
-
<div class="attachment-details">
|
369
|
-
<h2 class="title">
|
370
|
-
<a href="http://example.com/test.pdf" aria-describedby="attachment-123-accessibility-help">Attachment Title</a>
|
371
|
-
</h2>
|
372
|
-
<p class="metadata">
|
373
|
-
<span class="references">Ref: ISBN <span class="isbn">isbn-123</span></span>
|
374
|
-
<span class="unnumbered-paper">
|
375
|
-
Unnumbered command paper
|
376
|
-
</span>
|
377
|
-
</p>
|
378
|
-
<p>
|
379
|
-
<a href="http://example.com/order" class="order_url" title="Order a copy of the publication">Order a copy</a>(<span class="price">£12.30</span>)
|
380
|
-
</p>
|
381
|
-
<p class="opendocument-help">
|
382
|
-
This file is in an <a rel="external" href="https://en.wikipedia.org/wiki/OpenDocument_software">OpenDocument</a> format
|
383
|
-
</p>
|
384
|
-
<div data-module="toggle" class="accessibility-warning" id="attachment-123-accessibility-help">
|
385
|
-
<h2>This file may not be suitable for users of assistive technology.
|
386
|
-
<a class="toggler" href="#attachment-123-accessibility-request" data-controls="attachment-123-accessibility-request" data-expanded="false">Request an accessible format.</a>
|
387
|
-
</h2>
|
388
|
-
<p id="attachment-123-accessibility-request" class="js-hidden">
|
389
|
-
If you use assistive technology (eg a screen reader) and need a
|
390
|
-
version of this document in a more accessible format, please email <a href="mailto:govuk-feedback@digital.cabinet-office.gov.uk?subject=Request%20for%20%27Attachment%20Title%27%20in%20an%20alternative%20format&body=Details%20of%20document%20required%3A%0A%0A%20%20Title%3A%20Attachment%20Title%0A%20%20ISBN%3A%20isbn-123%0A%0APlease%20tell%20us%3A%0A%0A%20%201.%20What%20makes%20this%20format%20unsuitable%20for%20you%3F%0A%20%202.%20What%20format%20you%20would%20prefer%3F%0A">govuk-feedback@digital.cabinet-office.gov.uk</a>.
|
391
|
-
Please tell us what format you need. It will help us if you say what assistive technology you use.
|
392
|
-
</p>
|
393
|
-
</div>
|
394
|
-
</div>
|
395
|
-
</section>
|
396
|
-
}
|
397
|
-
assert_equal(compress_html(expected_html_output), compress_html(rendered))
|
398
|
-
end
|
399
|
-
|
400
347
|
test "attachment that isn't provided" do
|
401
348
|
govspeak = "[embed:attachments:906ac8b7-850d-45c6-98e0-9525c680f891]"
|
402
349
|
rendered = Govspeak::Document.new(govspeak).to_html
|
@@ -3,38 +3,66 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class GovspeakContactsTest < Minitest::Test
|
6
|
-
|
7
|
-
def build_contact(attrs={})
|
6
|
+
def build_contact(attrs = {})
|
8
7
|
{
|
9
|
-
id: attrs.fetch(:id, 123456),
|
10
8
|
content_id: attrs.fetch(:content_id, "4f3383e4-48a2-4461-a41d-f85ea8b89ba0"),
|
11
9
|
title: attrs.fetch(:title, "Government Digital Service"),
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
10
|
+
description: attrs.fetch(:description, ""),
|
11
|
+
details: {
|
12
|
+
post_addresses: attrs.fetch(
|
13
|
+
:post_addresses,
|
14
|
+
[
|
15
|
+
{
|
16
|
+
title: "",
|
17
|
+
street_address: "125 Kingsway",
|
18
|
+
locality: "Holborn",
|
19
|
+
region: "London",
|
20
|
+
postal_code: "WC2B 6NH",
|
21
|
+
world_location: "United Kingdom",
|
22
|
+
}
|
23
|
+
]
|
24
|
+
),
|
25
|
+
email_addresses: attrs.fetch(
|
26
|
+
:email_addresses,
|
27
|
+
[
|
28
|
+
{
|
29
|
+
title: "",
|
30
|
+
email: "people@digital.cabinet-office.gov.uk",
|
31
|
+
}
|
32
|
+
]
|
33
|
+
),
|
34
|
+
phone_numbers: attrs.fetch(
|
35
|
+
:phone_numbers,
|
36
|
+
[
|
37
|
+
{
|
38
|
+
title: "helpdesk",
|
39
|
+
number: "+4412345 67890",
|
40
|
+
}
|
41
|
+
]
|
42
|
+
),
|
43
|
+
contact_form_links: attrs.fetch(
|
44
|
+
:contact_form_links,
|
45
|
+
[
|
46
|
+
{
|
47
|
+
link: "https://www.gov.uk/contact"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
)
|
51
|
+
}
|
24
52
|
}
|
25
53
|
end
|
26
54
|
|
27
55
|
def compress_html(html)
|
28
|
-
html.gsub(/[\n\r]+[\s]*/,'')
|
56
|
+
html.gsub(/[\n\r]+[\s]*/, '')
|
29
57
|
end
|
30
58
|
|
31
59
|
test "contact is rendered when present in options[:contacts]" do
|
32
60
|
contact = build_contact
|
33
61
|
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
34
62
|
|
35
|
-
rendered = Govspeak::Document.new(govspeak,
|
63
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
36
64
|
expected_html_output = %{
|
37
|
-
<div id="
|
65
|
+
<div id="contact_4f3383e4-48a2-4461-a41d-f85ea8b89ba0" class="contact postal-address">
|
38
66
|
<div class="content">
|
39
67
|
<h3>Government Digital Service</h3>
|
40
68
|
<div class="vcard contact-inner">
|
@@ -49,6 +77,10 @@ class GovspeakContactsTest < Minitest::Test
|
|
49
77
|
<span class="type">Email</span>
|
50
78
|
<a href="mailto:people@digital.cabinet-office.gov.uk" class="email">people@digital.cabinet-office.gov.uk</a>
|
51
79
|
</p>
|
80
|
+
<p class="contact_form_url">
|
81
|
+
<span class="type">Contact form</span>
|
82
|
+
<a href="https://www.gov.uk/contact">https://www.gov.uk/con...</a>
|
83
|
+
</p>
|
52
84
|
<p class="tel">
|
53
85
|
<span class="type">helpdesk</span>
|
54
86
|
+4412345 67890
|
@@ -65,27 +97,16 @@ class GovspeakContactsTest < Minitest::Test
|
|
65
97
|
test "no contact is rendered when contact not present in options[:contacts]" do
|
66
98
|
contact = build_contact(content_id: "19f06142-1b4a-47ce-b257-964badd0a5e2")
|
67
99
|
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
68
|
-
rendered = Govspeak::Document.new(govspeak,
|
69
|
-
assert_match("", rendered)
|
70
|
-
end
|
71
|
-
|
72
|
-
test "no contact is rendered when no contacts are supplied" do
|
73
|
-
rendered = Govspeak::Document.new("[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]").to_html
|
100
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
74
101
|
assert_match("", rendered)
|
75
102
|
end
|
76
103
|
|
77
104
|
test "contact with no postal address omits the address info" do
|
78
|
-
contact = build_contact(
|
79
|
-
recipient: nil,
|
80
|
-
street_address: nil,
|
81
|
-
locality: nil,
|
82
|
-
region: nil,
|
83
|
-
postal_code: nil,
|
84
|
-
)
|
105
|
+
contact = build_contact(post_addresses: [])
|
85
106
|
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
86
|
-
rendered = Govspeak::Document.new(govspeak,
|
107
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
87
108
|
expected_html_output = %{
|
88
|
-
<div id="
|
109
|
+
<div id="contact_4f3383e4-48a2-4461-a41d-f85ea8b89ba0" class="contact">
|
89
110
|
<div class="content">
|
90
111
|
<h3>Government Digital Service</h3>
|
91
112
|
<div class="vcard contact-inner">
|
@@ -94,6 +115,10 @@ class GovspeakContactsTest < Minitest::Test
|
|
94
115
|
<span class="type">Email</span>
|
95
116
|
<a href="mailto:people@digital.cabinet-office.gov.uk" class="email">people@digital.cabinet-office.gov.uk</a>
|
96
117
|
</p>
|
118
|
+
<p class="contact_form_url">
|
119
|
+
<span class="type">Contact form</span>
|
120
|
+
<a href="https://www.gov.uk/contact">https://www.gov.uk/con...</a>
|
121
|
+
</p>
|
97
122
|
<p class="tel">
|
98
123
|
<span class="type">helpdesk</span>
|
99
124
|
+4412345 67890
|
@@ -106,11 +131,73 @@ class GovspeakContactsTest < Minitest::Test
|
|
106
131
|
assert_equal(compress_html(expected_html_output), compress_html(rendered))
|
107
132
|
end
|
108
133
|
|
109
|
-
test "
|
110
|
-
contact = build_contact(
|
134
|
+
test "contact with United Kingdom country address doesn't show the country" do
|
135
|
+
contact = build_contact(post_addresses: [
|
136
|
+
{
|
137
|
+
street_address: "125 Kingsway",
|
138
|
+
country_name: "United Kingdom",
|
139
|
+
}
|
140
|
+
])
|
141
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
142
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
143
|
+
expected = %{
|
144
|
+
<p class="adr">
|
145
|
+
<span class="street-address">125 Kingsway</span>
|
146
|
+
</p>
|
147
|
+
}
|
148
|
+
assert_match(compress_html(expected), compress_html(rendered))
|
149
|
+
end
|
150
|
+
|
151
|
+
test "contact with an empty postal address is not rendered" do
|
152
|
+
contact = build_contact(post_addresses: [
|
153
|
+
{
|
154
|
+
street_address: "",
|
155
|
+
}
|
156
|
+
])
|
157
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
158
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
159
|
+
refute_match(%{<p class="adr">}, compress_html(rendered))
|
160
|
+
end
|
161
|
+
|
162
|
+
test "contact with an empty email address is not rendered" do
|
163
|
+
contact = build_contact(email_addresses: [
|
164
|
+
{
|
165
|
+
email: "",
|
166
|
+
}
|
167
|
+
])
|
168
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
169
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
170
|
+
refute_match(%{<p class="email">}, compress_html(rendered))
|
171
|
+
end
|
172
|
+
|
173
|
+
test "contact with an empty contact form is not rendered" do
|
174
|
+
contact = build_contact(contact_form_links: [
|
175
|
+
{
|
176
|
+
link: "",
|
177
|
+
}
|
178
|
+
])
|
179
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
180
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
181
|
+
refute_match(%{<p class="contact_form_url">}, compress_html(rendered))
|
182
|
+
end
|
183
|
+
|
184
|
+
test "contact with an empty phone number is not rendered" do
|
185
|
+
contact = build_contact(phone_numbers: [
|
186
|
+
{
|
187
|
+
number: "",
|
188
|
+
}
|
189
|
+
])
|
190
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
191
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
192
|
+
refute_match(%{<p class="tel">}, compress_html(rendered))
|
193
|
+
end
|
194
|
+
|
195
|
+
test "it auto links text in the description" do
|
196
|
+
contact = build_contact(description: "My description about https://www.gov.uk")
|
197
|
+
|
111
198
|
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
112
|
-
rendered = Govspeak::Document.new(govspeak,
|
113
|
-
|
114
|
-
|
199
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
|
200
|
+
assert_match(%{<p class="comments">My description about <a href="https://www.gov.uk">https://www.gov.uk</a></p>},
|
201
|
+
compress_html(rendered))
|
115
202
|
end
|
116
203
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GovspeakExtractContactContentIdsTest < Minitest::Test
|
6
|
+
test "contact content ids can be extracted from govspeak" do
|
7
|
+
content_id1 = SecureRandom.uuid
|
8
|
+
content_id2 = SecureRandom.uuid
|
9
|
+
govspeak = "Some text with a contact\n [Contact:#{content_id1}]\n\n[Contact:#{content_id2}]"
|
10
|
+
|
11
|
+
assert_equal(Govspeak::Document.new(govspeak).extract_contact_content_ids, [content_id1, content_id2])
|
12
|
+
end
|
13
|
+
|
14
|
+
test "only extracts contact content ids that are UUIDs" do
|
15
|
+
govspeak = "[Contact:12345]"
|
16
|
+
|
17
|
+
refute_equal(
|
18
|
+
Govspeak::Document.new(govspeak).extract_contact_content_ids,
|
19
|
+
%w[12345],
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "same contact repeated multiple times only yields a single result" do
|
24
|
+
content_id = SecureRandom.uuid
|
25
|
+
govspeak = "[Contact:#{content_id}]\n[Contact:#{content_id}][Contact:#{content_id}]"
|
26
|
+
|
27
|
+
assert_equal(Govspeak::Document.new(govspeak).extract_contact_content_ids, [content_id])
|
28
|
+
end
|
29
|
+
end
|
@@ -45,7 +45,7 @@ class GovspeakLinkExtractorTest < Minitest::Test
|
|
45
45
|
end
|
46
46
|
|
47
47
|
test "Other content is not extracted from the body" do
|
48
|
-
refute_includes [
|
48
|
+
refute_includes %w[Heading], links
|
49
49
|
end
|
50
50
|
|
51
51
|
test "Links are not extracted if they begin with #" do
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class GovspeakStructuredHeadersTest < Minitest::Test
|
4
|
-
|
5
4
|
def document_body
|
6
5
|
%{
|
7
6
|
## Heading 1
|
@@ -46,7 +45,7 @@ class GovspeakStructuredHeadersTest < Minitest::Test
|
|
46
45
|
end
|
47
46
|
|
48
47
|
test "h2s are extracted as top level headings" do
|
49
|
-
expected_headings =
|
48
|
+
expected_headings = ["Heading 1", "Heading 2", "Heading 3", "Heading 4", "Heading 5"]
|
50
49
|
|
51
50
|
assert_equal expected_headings, structured_headers.map(&:text)
|
52
51
|
end
|
@@ -72,33 +71,33 @@ class GovspeakStructuredHeadersTest < Minitest::Test
|
|
72
71
|
serialized_headers = structured_headers[1].to_h
|
73
72
|
|
74
73
|
expected_serialized_headers = {
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
74
|
+
text: "Heading 2",
|
75
|
+
level: 2,
|
76
|
+
id: "heading-2",
|
77
|
+
headers: [
|
79
78
|
{
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
79
|
+
text: "Sub heading 2.1",
|
80
|
+
level: 3,
|
81
|
+
id: "sub-heading-21",
|
82
|
+
headers: [],
|
84
83
|
},
|
85
84
|
{
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
85
|
+
text: "Sub heading 2.2",
|
86
|
+
level: 3,
|
87
|
+
id: "sub-heading-22",
|
88
|
+
headers: [
|
90
89
|
{
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
90
|
+
text: "Sub sub heading 2.2.1",
|
91
|
+
level: 4,
|
92
|
+
id: "sub-sub-heading-221",
|
93
|
+
headers: []
|
95
94
|
},
|
96
95
|
],
|
97
96
|
},
|
98
97
|
{
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
98
|
+
text: "Sub heading 2.3",
|
99
|
+
level: 3, id: "sub-heading-23",
|
100
|
+
headers: []
|
102
101
|
},
|
103
102
|
],
|
104
103
|
}
|
data/test/govspeak_test.rb
CHANGED
@@ -9,27 +9,27 @@ class GovspeakTest < Minitest::Test
|
|
9
9
|
include GovspeakTestHelper
|
10
10
|
|
11
11
|
test "simple smoke-test" do
|
12
|
-
rendered =
|
12
|
+
rendered = Govspeak::Document.new("*this is markdown*").to_html
|
13
13
|
assert_equal "<p><em>this is markdown</em></p>\n", rendered
|
14
14
|
end
|
15
15
|
|
16
16
|
test "simple smoke-test for simplified API" do
|
17
|
-
rendered =
|
17
|
+
rendered = Govspeak::Document.to_html("*this is markdown*")
|
18
18
|
assert_equal "<p><em>this is markdown</em></p>\n", rendered
|
19
19
|
end
|
20
20
|
|
21
21
|
test "highlight-answer block extension" do
|
22
|
-
rendered =
|
23
|
-
assert_equal %
|
22
|
+
rendered = Govspeak::Document.new("this \n{::highlight-answer}Lead in to *BIG TEXT*\n{:/highlight-answer}").to_html
|
23
|
+
assert_equal %{<p>this</p>\n\n<div class="highlight-answer">\n<p>Lead in to <em>BIG TEXT</em></p>\n</div>\n}, rendered
|
24
24
|
end
|
25
25
|
|
26
26
|
test "stat-headline block extension" do
|
27
|
-
rendered =
|
28
|
-
assert_equal %
|
27
|
+
rendered = Govspeak::Document.new("this \n{stat-headline}*13.8bn* Age of the universe in years{/stat-headline}").to_html
|
28
|
+
assert_equal %{<p>this</p>\n\n<aside class="stat-headline">\n<p><em>13.8bn</em> Age of the universe in years</p>\n</aside>\n}, rendered
|
29
29
|
end
|
30
30
|
|
31
31
|
test "extracts headers with text, level and generated id" do
|
32
|
-
document =
|
32
|
+
document = Govspeak::Document.new %{
|
33
33
|
# Big title
|
34
34
|
|
35
35
|
### Small subtitle
|
@@ -44,7 +44,7 @@ class GovspeakTest < Minitest::Test
|
|
44
44
|
end
|
45
45
|
|
46
46
|
test "extracts different ids for duplicate headers" do
|
47
|
-
document =
|
47
|
+
document = Govspeak::Document.new("## Duplicate header\n\n## Duplicate header")
|
48
48
|
assert_equal [
|
49
49
|
Govspeak::Header.new('Duplicate header', 2, 'duplicate-header'),
|
50
50
|
Govspeak::Header.new('Duplicate header', 2, 'duplicate-header-1')
|
@@ -52,7 +52,7 @@ class GovspeakTest < Minitest::Test
|
|
52
52
|
end
|
53
53
|
|
54
54
|
test "extracts headers when nested inside blocks" do
|
55
|
-
document =
|
55
|
+
document = Govspeak::Document.new %{
|
56
56
|
# First title
|
57
57
|
|
58
58
|
<div markdown="1">
|
@@ -77,7 +77,7 @@ class GovspeakTest < Minitest::Test
|
|
77
77
|
end
|
78
78
|
|
79
79
|
test "extracts headers with explicitly specified ids" do
|
80
|
-
document =
|
80
|
+
document = Govspeak::Document.new %{
|
81
81
|
# First title
|
82
82
|
|
83
83
|
## Second title {#special}
|
@@ -105,23 +105,23 @@ Teston
|
|
105
105
|
end
|
106
106
|
|
107
107
|
test "should convert barchart" do
|
108
|
-
input =
|
109
|
-
|col|
|
110
|
-
|---|
|
111
|
-
|val|
|
112
|
-
{barchart}
|
113
|
-
|
108
|
+
input = <<~GOVSPEAK
|
109
|
+
|col|
|
110
|
+
|---|
|
111
|
+
|val|
|
112
|
+
{barchart}
|
113
|
+
GOVSPEAK
|
114
114
|
html = Govspeak::Document.new(input).to_html
|
115
115
|
assert_equal %{<table class=\"js-barchart-table mc-auto-outdent\">\n <thead>\n <tr>\n <th>col</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>val</td>\n </tr>\n </tbody>\n</table>\n}, html
|
116
116
|
end
|
117
117
|
|
118
118
|
test "should convert barchart with stacked compact and negative" do
|
119
|
-
input =
|
120
|
-
|col|
|
121
|
-
|---|
|
122
|
-
|val|
|
123
|
-
{barchart stacked compact negative}
|
124
|
-
|
119
|
+
input = <<~GOVSPEAK
|
120
|
+
|col|
|
121
|
+
|---|
|
122
|
+
|val|
|
123
|
+
{barchart stacked compact negative}
|
124
|
+
GOVSPEAK
|
125
125
|
html = Govspeak::Document.new(input).to_html
|
126
126
|
assert_equal %{<table class=\"js-barchart-table mc-stacked compact mc-negative mc-auto-outdent\">\n <thead>\n <tr>\n <th>col</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>val</td>\n </tr>\n </tbody>\n</table>\n}, html
|
127
127
|
end
|
@@ -331,17 +331,17 @@ Teston
|
|
331
331
|
test "should treat a mailto as internal" do
|
332
332
|
html = Govspeak::Document.new("[link](mailto:a@b.com)").to_html
|
333
333
|
refute html.include?('rel="external"')
|
334
|
-
assert_equal %
|
334
|
+
assert_equal %{<p><a href="mailto:a@b.com">link</a></p>\n}, deobfuscate_mailto(html)
|
335
335
|
end
|
336
336
|
|
337
337
|
test "permits mailto:// URI" do
|
338
338
|
html = Govspeak::Document.new("[link](mailto://a@b.com)").to_html
|
339
|
-
assert_equal %
|
339
|
+
assert_equal %{<p><a rel="external" href="mailto://a@b.com">link</a></p>\n}, deobfuscate_mailto(html)
|
340
340
|
end
|
341
341
|
|
342
342
|
test "permits dud mailto: URI" do
|
343
343
|
html = Govspeak::Document.new("[link](mailto:)").to_html
|
344
|
-
assert_equal %
|
344
|
+
assert_equal %{<p><a href="mailto:">link</a></p>\n}, deobfuscate_mailto(html)
|
345
345
|
end
|
346
346
|
|
347
347
|
test "permits trailing whitespace in an URI" do
|
@@ -420,11 +420,12 @@ Teston
|
|
420
420
|
assert_text_output "Click here to start the tool"
|
421
421
|
end
|
422
422
|
|
423
|
-
test_given_govspeak "
|
423
|
+
test_given_govspeak "
|
424
|
+
Here is some text
|
424
425
|
|
425
|
-
$CTA
|
426
|
-
Click here to start the tool
|
427
|
-
$CTA
|
426
|
+
$CTA
|
427
|
+
Click here to start the tool
|
428
|
+
$CTA
|
428
429
|
" do
|
429
430
|
assert_html_output %{
|
430
431
|
<p>Here is some text</p>
|
@@ -639,17 +640,17 @@ $CTA
|
|
639
640
|
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
|
640
641
|
%{</figure>}
|
641
642
|
)
|
643
|
+
end
|
642
644
|
end
|
643
|
-
end
|
644
645
|
|
645
|
-
test "alt text of referenced images is escaped" do
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
646
|
+
test "alt text of referenced images is escaped" do
|
647
|
+
images = [OpenStruct.new(alt_text: %{my alt '&"<>}, url: "http://example.com/image.jpg")]
|
648
|
+
given_govspeak "!!1", images do
|
649
|
+
assert_html_output(
|
650
|
+
%{<figure class="image embedded">} +
|
651
|
+
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&"<>"></div>} +
|
652
|
+
%{</figure>}
|
653
|
+
)
|
653
654
|
end
|
654
655
|
end
|
655
656
|
|
@@ -657,7 +658,7 @@ test "alt text of referenced images is escaped" do
|
|
657
658
|
doc = Govspeak::Document.new("!!1")
|
658
659
|
doc.images = []
|
659
660
|
|
660
|
-
assert_equal %
|
661
|
+
assert_equal %{\n}, doc.to_html
|
661
662
|
end
|
662
663
|
|
663
664
|
test "adds image caption if given" do
|
@@ -838,7 +839,7 @@ $PriorityList:1
|
|
838
839
|
end
|
839
840
|
|
840
841
|
test "should remove quotes surrounding a blockquote" do
|
841
|
-
govspeak = %
|
842
|
+
govspeak = %{
|
842
843
|
He said:
|
843
844
|
|
844
845
|
> "I'm not sure what you mean!"
|