govspeak 3.5.1 → 3.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/govspeak/header_extractor.rb +38 -4
- data/lib/govspeak/version.rb +1 -1
- data/test/govspeak_structured_headers_test.rb +1 -1
- data/test/govspeak_test.rb +38 -1
- data/test/html_sanitizer_test.rb +1 -1
- data/test/html_validator_test.rb +1 -1
- data/test/test_helper.rb +2 -2
- data/test/with_deep_merge_test.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62bbf045a81a14edccdebbc6f9bfe8b16053fe83
|
4
|
+
data.tar.gz: 51b63bd95386ba9a1409b8aeab3f9fed85dc169f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 144b044eaac74204158ab084b8aa65faa911b0f1f37aee17037950a3a6f89b0da67f2813e448bbeb435429db02fe15db0c087c9ad114d396643ea030ad7e98df
|
7
|
+
data.tar.gz: 2bbad23f71d71361666a73fb59a93eea150134c5e3239c93ed9726e1c6894de96184ae88a2628b9f3201440d98411bc13486d4ddb298eb5a4510da74f1e1e1c6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 3.5.2
|
2
|
+
|
3
|
+
* Fix a couple of issues with the [header_extractor](https://github.com/alphagov/govspeak/blob/master/lib/govspeak/header_extractor.rb). The method now picks up headers nested inside `blocks`, and when ID's are [explicitly set](http://kramdown.gettalong.org/syntax.html#specifying-a-header-id). See [https://github.com/alphagov/govspeak/pull/66](https://github.com/alphagov/govspeak/pull/66) for more.
|
4
|
+
|
1
5
|
## 3.5.1
|
2
6
|
|
3
7
|
* Continue to support non-strict URIs in links on Ruby 2.2.x. See [https://github.com/alphagov/govspeak/issues/57](https://github.com/alphagov/govspeak/issues/57)
|
@@ -3,11 +3,45 @@ module Govspeak
|
|
3
3
|
|
4
4
|
class HeaderExtractor < Kramdown::Converter::Base
|
5
5
|
def convert(doc)
|
6
|
-
|
6
|
+
headers = []
|
7
|
+
|
8
|
+
doc.root.children.each do |el|
|
7
9
|
if el.type == :header
|
8
|
-
|
10
|
+
headers << build_header(el)
|
11
|
+
next
|
12
|
+
end
|
13
|
+
|
14
|
+
headers << find_headers(el) if el.type == :html_element
|
15
|
+
end
|
16
|
+
|
17
|
+
headers.flatten.compact
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def id(el)
|
22
|
+
el.attr.fetch('id', generate_id(el.options[:raw_text]))
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_header(el)
|
26
|
+
Header.new(el.options[:raw_text], el.options[:level], id(el))
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_headers(parent)
|
30
|
+
headers = []
|
31
|
+
|
32
|
+
if parent.type == :header
|
33
|
+
headers << build_header(parent)
|
34
|
+
elsif parent.type == :html_element
|
35
|
+
parent.children.each do |child|
|
36
|
+
if child.type == :header
|
37
|
+
headers << build_header(child)
|
38
|
+
elsif child.children.size > 0
|
39
|
+
headers << find_headers(child)
|
40
|
+
end
|
9
41
|
end
|
10
|
-
end
|
42
|
+
end
|
43
|
+
|
44
|
+
headers
|
11
45
|
end
|
12
46
|
end
|
13
|
-
end
|
47
|
+
end
|
data/lib/govspeak/version.rb
CHANGED
data/test/govspeak_test.rb
CHANGED
@@ -5,7 +5,7 @@ require 'govspeak_test_helper'
|
|
5
5
|
|
6
6
|
require 'ostruct'
|
7
7
|
|
8
|
-
class GovspeakTest < Test
|
8
|
+
class GovspeakTest < Minitest::Test
|
9
9
|
include GovspeakTestHelper
|
10
10
|
|
11
11
|
test "simple smoke-test" do
|
@@ -56,6 +56,43 @@ class GovspeakTest < Test::Unit::TestCase
|
|
56
56
|
], document.headers
|
57
57
|
end
|
58
58
|
|
59
|
+
test "extracts headers when nested inside blocks" do
|
60
|
+
document = Govspeak::Document.new %{
|
61
|
+
# First title
|
62
|
+
|
63
|
+
<div markdown="1">
|
64
|
+
## Nested subtitle
|
65
|
+
</div>
|
66
|
+
|
67
|
+
<div>
|
68
|
+
<div markdown="1">
|
69
|
+
### Double nested subtitle
|
70
|
+
</div>
|
71
|
+
<div markdown="1">
|
72
|
+
### Second double subtitle
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
}
|
76
|
+
assert_equal [
|
77
|
+
Govspeak::Header.new('First title', 1, 'first-title'),
|
78
|
+
Govspeak::Header.new('Nested subtitle', 2, 'nested-subtitle'),
|
79
|
+
Govspeak::Header.new('Double nested subtitle', 3, 'double-nested-subtitle'),
|
80
|
+
Govspeak::Header.new('Second double subtitle', 3, 'second-double-subtitle')
|
81
|
+
], document.headers
|
82
|
+
end
|
83
|
+
|
84
|
+
test "extracts headers with explicitly specified ids" do
|
85
|
+
document = Govspeak::Document.new %{
|
86
|
+
# First title
|
87
|
+
|
88
|
+
## Second title {#special}
|
89
|
+
}
|
90
|
+
assert_equal [
|
91
|
+
Govspeak::Header.new('First title', 1, 'first-title'),
|
92
|
+
Govspeak::Header.new('Second title', 2, 'special'),
|
93
|
+
], document.headers
|
94
|
+
end
|
95
|
+
|
59
96
|
test "extracts text with no HTML and normalised spacing" do
|
60
97
|
input = "# foo\n\nbar baz "
|
61
98
|
doc = Govspeak::Document.new(input)
|
data/test/html_sanitizer_test.rb
CHANGED
data/test/html_validator_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -9,9 +9,9 @@ $:.unshift(File.expand_path("../lib")) unless $:.include?(File.expand_path("../l
|
|
9
9
|
require 'bundler'
|
10
10
|
Bundler.setup :default, :development, :test
|
11
11
|
|
12
|
-
require '
|
12
|
+
require 'minitest/autorun'
|
13
13
|
|
14
|
-
class Test
|
14
|
+
class Minitest::Test
|
15
15
|
class << self
|
16
16
|
def test(name, &block)
|
17
17
|
clean_name = name.gsub(/\s+/,'_')
|
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: 3.5.
|
4
|
+
version: 3.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Griffiths
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: kramdown
|
@@ -109,6 +109,20 @@ dependencies:
|
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: 1.1.1
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: minitest
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 5.8.3
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 5.8.3
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: simplecov
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|