govspeak 1.5.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/govspeak.rb +11 -0
- data/lib/govspeak/kramdown_overrides.rb +39 -0
- data/lib/govspeak/version.rb +1 -1
- data/test/govspeak_test.rb +22 -0
- metadata +5 -4
data/CHANGELOG.md
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -3,6 +3,7 @@ require 'govspeak/header_extractor'
|
|
3
3
|
require 'govspeak/structured_header_extractor'
|
4
4
|
require 'govspeak/html_validator'
|
5
5
|
require 'govspeak/html_sanitizer'
|
6
|
+
require 'govspeak/kramdown_overrides'
|
6
7
|
require 'kramdown/parser/kramdown_with_automatic_external_links'
|
7
8
|
require 'htmlentities'
|
8
9
|
|
@@ -159,6 +160,16 @@ module Govspeak
|
|
159
160
|
%{<div class="address"><div class="adr org fn"><p>\n#{body.sub("\n", "").gsub("\n", "<br />")}\n</p></div></div>\n}
|
160
161
|
}
|
161
162
|
|
163
|
+
extension("legislative list", /\$LegislativeList\s*$(.*?)(?:^\s*$|\Z)/m) do |body|
|
164
|
+
Govspeak::KramdownOverrides.with_kramdown_ordered_lists_disabled do
|
165
|
+
Kramdown::Document.new(body.strip).to_html.tap do |doc|
|
166
|
+
doc.gsub!('<ul>', '<ol>')
|
167
|
+
doc.gsub!('</ul>', '</ol>')
|
168
|
+
doc.sub!('<ol>', '<ol class="legislative-list">')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
162
173
|
extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body|
|
163
174
|
steps ||= 0
|
164
175
|
body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/) do |b|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Govspeak
|
2
|
+
module KramdownOverrides
|
3
|
+
# This depends on two internal parts of Kramdown.
|
4
|
+
# 1. Parser registry (kramdown/parser/kramdown.rb#define_parser)
|
5
|
+
# 2. Kramdown list regexes (kramdown/parser/kramdown/list.rb)
|
6
|
+
# Updating the Kramdown gem therefore also means updating this file to to
|
7
|
+
# match Kramdown's internals.
|
8
|
+
|
9
|
+
def self.with_kramdown_ordered_lists_disabled
|
10
|
+
original_list_start = list_start
|
11
|
+
redefine_kramdown_const(:LIST_START, list_start_ul)
|
12
|
+
list_parser = kramdown_parsers.delete(:list)
|
13
|
+
Kramdown::Parser::Kramdown.define_parser(:list, list_start_ul)
|
14
|
+
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
redefine_kramdown_const(:LIST_START, original_list_start)
|
18
|
+
kramdown_parsers[:list] = list_parser
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def self.list_start
|
23
|
+
Kramdown::Parser::Kramdown::LIST_START
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.list_start_ul
|
27
|
+
Kramdown::Parser::Kramdown::LIST_START_UL
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.kramdown_parsers
|
31
|
+
Kramdown::Parser::Kramdown.class_variable_get("@@parsers")
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.redefine_kramdown_const(const, value)
|
35
|
+
Kramdown::Parser::Kramdown.send(:remove_const, const)
|
36
|
+
Kramdown::Parser::Kramdown.send(:const_set, const, value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/govspeak/version.rb
CHANGED
data/test/govspeak_test.rb
CHANGED
@@ -396,6 +396,28 @@ $CTA
|
|
396
396
|
assert_text_output "unordered list step list"
|
397
397
|
end
|
398
398
|
|
399
|
+
test_given_govspeak "
|
400
|
+
$LegislativeList
|
401
|
+
* 1. The quick
|
402
|
+
* 2. Brown fox
|
403
|
+
* a) Jumps over
|
404
|
+
* b) The lazy
|
405
|
+
* 3. Dog
|
406
|
+
" do
|
407
|
+
assert_html_output %{
|
408
|
+
<ol class="legislative-list">
|
409
|
+
<li>1. The quick</li>
|
410
|
+
<li>2. Brown fox
|
411
|
+
<ol>
|
412
|
+
<li>a) Jumps over</li>
|
413
|
+
<li>b) The lazy</li>
|
414
|
+
</ol>
|
415
|
+
</li>
|
416
|
+
<li>3. Dog</li>
|
417
|
+
</ol>
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
399
421
|
test_given_govspeak "
|
400
422
|
Zippy, Bungle and George did not qualify for the tax exemption in s428. They filled in their tax return accordingly.
|
401
423
|
" do
|
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: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-06-
|
13
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: kramdown
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/kramdown/parser/kramdown_with_automatic_external_links.rb
|
154
154
|
- lib/govspeak.rb
|
155
155
|
- lib/govspeak/html_validator.rb
|
156
|
+
- lib/govspeak/kramdown_overrides.rb
|
156
157
|
- lib/govspeak/version.rb
|
157
158
|
- lib/govspeak/html_sanitizer.rb
|
158
159
|
- lib/govspeak/header_extractor.rb
|
@@ -181,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
182
|
version: '0'
|
182
183
|
segments:
|
183
184
|
- 0
|
184
|
-
hash:
|
185
|
+
hash: 3370036994273431811
|
185
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
187
|
none: false
|
187
188
|
requirements:
|
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
191
|
version: '0'
|
191
192
|
segments:
|
192
193
|
- 0
|
193
|
-
hash:
|
194
|
+
hash: 3370036994273431811
|
194
195
|
requirements: []
|
195
196
|
rubyforge_project:
|
196
197
|
rubygems_version: 1.8.23
|