govspeak 0.8.4 → 0.8.5
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.
- data/lib/govspeak.rb +7 -2
- data/lib/govspeak/header_extractor.rb +13 -0
- data/test/govspeak_test.rb +39 -4
- metadata +8 -7
data/lib/govspeak.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'kramdown'
|
2
|
+
require 'govspeak/header_extractor'
|
2
3
|
|
3
4
|
module Govspeak
|
4
5
|
|
@@ -21,6 +22,10 @@ module Govspeak
|
|
21
22
|
@doc.to_html
|
22
23
|
end
|
23
24
|
|
25
|
+
def headers
|
26
|
+
Govspeak::HeaderExtractor.convert(@doc).first
|
27
|
+
end
|
28
|
+
|
24
29
|
def preprocess(source)
|
25
30
|
@@extensions.each do |title,regexp,block|
|
26
31
|
source.gsub!(regexp) {|match|
|
@@ -66,11 +71,11 @@ module Govspeak
|
|
66
71
|
}
|
67
72
|
|
68
73
|
extension('important', surrounded_by("@")) { |body|
|
69
|
-
%{\n\n<h3 class="advisory"
|
74
|
+
%{\n\n<h3 class="advisory">#{Kramdown::Document.new(body.strip).to_html}</h3>\n}
|
70
75
|
}
|
71
76
|
|
72
77
|
extension('helpful', surrounded_by("%")) { |body|
|
73
|
-
%{\n\n<div class="application-notice help-notice">\n
|
78
|
+
%{\n\n<div class="application-notice help-notice">\n#{Kramdown::Document.new(body.strip).to_html}</div>\n}
|
74
79
|
}
|
75
80
|
|
76
81
|
extension('map_link', surrounded_by("((", "))")) { |body|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Govspeak
|
2
|
+
Header = Struct.new(:text, :level, :id)
|
3
|
+
|
4
|
+
class HeaderExtractor < Kramdown::Converter::Base
|
5
|
+
def convert(doc)
|
6
|
+
doc.root.children.map do |el|
|
7
|
+
if el.type == :header
|
8
|
+
Header.new(el.options[:raw_text], el.options[:level], generate_id(el.options[:raw_text]))
|
9
|
+
end
|
10
|
+
end.compact
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/test/govspeak_test.rb
CHANGED
@@ -23,6 +23,29 @@ class GovspeakTest < Test::Unit::TestCase
|
|
23
23
|
assert_equal "<p>this </p>\n\n<p><em>si</em></p>\n\n<p>markdown</p>\n", rendered
|
24
24
|
end
|
25
25
|
|
26
|
+
test "extracts headers with text, level and generated id" do
|
27
|
+
document = Govspeak::Document.new %{
|
28
|
+
# Big title
|
29
|
+
|
30
|
+
### Small subtitle
|
31
|
+
|
32
|
+
## Medium title
|
33
|
+
}
|
34
|
+
assert_equal [
|
35
|
+
Govspeak::Header.new('Big title', 1, 'big-title'),
|
36
|
+
Govspeak::Header.new('Small subtitle', 3, 'small-subtitle'),
|
37
|
+
Govspeak::Header.new('Medium title', 2, 'medium-title')
|
38
|
+
], document.headers
|
39
|
+
end
|
40
|
+
|
41
|
+
test "extracts different ids for duplicate headers" do
|
42
|
+
document = Govspeak::Document.new("## Duplicate header\n\n## Duplicate header")
|
43
|
+
assert_equal [
|
44
|
+
Govspeak::Header.new('Duplicate header', 2, 'duplicate-header'),
|
45
|
+
Govspeak::Header.new('Duplicate header', 2, 'duplicate-header-1')
|
46
|
+
], document.headers
|
47
|
+
end
|
48
|
+
|
26
49
|
test "govspark extensions" do
|
27
50
|
markdown_regression_tests = [
|
28
51
|
{
|
@@ -44,13 +67,15 @@ class GovspeakTest < Test::Unit::TestCase
|
|
44
67
|
</div>}
|
45
68
|
}, {
|
46
69
|
input: "@ I am very important @",
|
47
|
-
output: %{<h3 class="advisory"><
|
70
|
+
output: %{<h3 class="advisory"><p>I am very important</p>
|
71
|
+
</h3>}
|
48
72
|
}, {
|
49
73
|
input: "The following is very important
|
50
74
|
@ I am very important @",
|
51
75
|
output: %{<p>The following is very important</p>
|
52
76
|
|
53
|
-
<h3 class="advisory"><
|
77
|
+
<h3 class="advisory"><p>I am very important</p>
|
78
|
+
</h3>}
|
54
79
|
}, {
|
55
80
|
input: "% I am very helpful %",
|
56
81
|
output: %{<div class="application-notice help-notice">
|
@@ -156,15 +181,25 @@ end
|
|
156
181
|
end
|
157
182
|
|
158
183
|
test "devolved markdown sections" do
|
159
|
-
input = ":scotland: I am very devolved
|
184
|
+
input = ":scotland: I am very devolved\n and very scottish \n:scotland:"
|
160
185
|
output = '<div class="devolved-content scotland">
|
161
186
|
<p class="devolved-header">This section applies to Scotland</p>
|
162
|
-
<div class="devolved-body"><p>I am very devolved
|
187
|
+
<div class="devolved-body"><p>I am very devolved
|
163
188
|
and very scottish</p>
|
164
189
|
</div>
|
165
190
|
</div>
|
166
191
|
'
|
167
192
|
|
193
|
+
assert_equal output, Govspeak::Document.new(input).to_html
|
194
|
+
end
|
195
|
+
|
196
|
+
test "links inside markdown boxes" do
|
197
|
+
input = "@ Message with [a link](http://foo.bar/)@"
|
198
|
+
output = %{
|
199
|
+
<h3 class="advisory"><p>Message with <a href="http://foo.bar/">a link</a></p>
|
200
|
+
</h3>
|
201
|
+
}
|
202
|
+
|
168
203
|
assert_equal output, Govspeak::Document.new(input).to_html
|
169
204
|
end
|
170
205
|
|
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: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-20 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: kramdown
|
17
|
-
requirement: &
|
17
|
+
requirement: &70126712036920 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.13.3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70126712036920
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &70126712036220 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 0.8.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70126712036220
|
37
37
|
description: ! "A set of extensions to markdown layered on top of the kramdown \nlibrary
|
38
38
|
for use in the UK Government Single Domain project"
|
39
39
|
email:
|
@@ -43,6 +43,7 @@ executables: []
|
|
43
43
|
extensions: []
|
44
44
|
extra_rdoc_files: []
|
45
45
|
files:
|
46
|
+
- lib/govspeak/header_extractor.rb
|
46
47
|
- lib/govspeak.rb
|
47
48
|
- Gemfile
|
48
49
|
- Rakefile
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
version: '0'
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.12
|
72
73
|
signing_key:
|
73
74
|
specification_version: 3
|
74
75
|
summary: Markup language for single domain
|