jekyll-toc 0.4.0.rc → 0.4.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jekyll-toc.gemspec +0 -4
- data/lib/table_of_contents/parser.rb +8 -6
- data/lib/version.rb +1 -1
- data/test/test_kramdown_list.rb +125 -0
- data/test/test_various_toc_html.rb +51 -23
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81dc11ec036241d6eed38ef5cddd5014ed2d12d7
|
4
|
+
data.tar.gz: 98c037df71e8684555a75f36fb29bdddf4826189
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 532db0dafa5253716f397e257b5256091e826a98be80644d5b089809e124bc5c9ab76f339786840f54259443ab821fee9ce6d4863c2f331aabda75dcad9e9a1c
|
7
|
+
data.tar.gz: bfd2b4fc0a808179e2e5d1caf2e535610e4ae6702733706b9e5e83e327c11d89a7aca5cb8d4d313d6e4e7388a10bc73b8423392cb931f89b1be03122657dc6ab
|
data/jekyll-toc.gemspec
CHANGED
@@ -15,10 +15,6 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
-
spec.post_install_message = %q(As of jekyll-toc 0.3, nested toc is supported! Please make sure your toc is not broken after update jekyll-toc.
|
19
|
-
|
20
|
-
For more info: https://github.com/toshimaru/jekyll-toc/wiki/0.3-Upgrade-Guide)
|
21
|
-
|
22
18
|
spec.required_ruby_version = '>= 2.1.0'
|
23
19
|
|
24
20
|
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
@@ -4,15 +4,13 @@ module Jekyll
|
|
4
4
|
class Parser
|
5
5
|
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u
|
6
6
|
|
7
|
-
attr_reader :doc
|
8
|
-
|
9
7
|
def initialize(html)
|
10
8
|
@doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
11
9
|
@entries = parse_content
|
12
10
|
end
|
13
11
|
|
14
12
|
def build_toc
|
15
|
-
%(<ul class="section-nav">\n#{build_toc_list(@entries)}</ul>)
|
13
|
+
%(<ul class="section-nav">\n#{build_toc_list(@entries, last_ul_used: true)}</ul>)
|
16
14
|
end
|
17
15
|
|
18
16
|
def inject_anchors_into_html
|
@@ -60,7 +58,7 @@ module Jekyll
|
|
60
58
|
end
|
61
59
|
|
62
60
|
# Returns the list items for entries
|
63
|
-
def build_toc_list(entries)
|
61
|
+
def build_toc_list(entries, last_ul_used: false)
|
64
62
|
i = 0
|
65
63
|
toc_list = ''
|
66
64
|
min_h_num = entries.map { |e| e[:h_num] }.min
|
@@ -75,7 +73,7 @@ module Jekyll
|
|
75
73
|
next_entry = entries[i + 1]
|
76
74
|
if next_entry[:h_num] > min_h_num
|
77
75
|
nest_entries = get_nest_entries(entries[i + 1, entries.count], min_h_num)
|
78
|
-
toc_list << %(\n<ul>\n#{build_toc_list(nest_entries)}</ul>\n)
|
76
|
+
toc_list << %(\n<ul>\n#{build_toc_list(nest_entries, last_ul_used: true)}</ul>\n)
|
79
77
|
i += nest_entries.count
|
80
78
|
end
|
81
79
|
end
|
@@ -84,7 +82,11 @@ module Jekyll
|
|
84
82
|
elsif entry[:h_num] > min_h_num
|
85
83
|
# If the current entry should be indented in the list, generate a sublist
|
86
84
|
nest_entries = get_nest_entries(entries[i, entries.count], min_h_num)
|
87
|
-
|
85
|
+
if last_ul_used
|
86
|
+
toc_list << build_toc_list(nest_entries, last_ul_used: true)
|
87
|
+
else
|
88
|
+
toc_list << %(<ul>\n#{build_toc_list(nest_entries, last_ul_used: true)}</ul>\n)
|
89
|
+
end
|
88
90
|
i += nest_entries.count - 1
|
89
91
|
end
|
90
92
|
i += 1
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestKramdownList < Minitest::Test
|
4
|
+
def test_kramdown_list_1
|
5
|
+
text = <<-MARKDOWN
|
6
|
+
* level-1
|
7
|
+
* level-2
|
8
|
+
* level-3
|
9
|
+
* level-4
|
10
|
+
* level-5
|
11
|
+
MARKDOWN
|
12
|
+
expected = <<-HTML
|
13
|
+
<ul>
|
14
|
+
<li>level-1
|
15
|
+
<ul>
|
16
|
+
<li>level-2
|
17
|
+
<ul>
|
18
|
+
<li>level-3
|
19
|
+
<ul>
|
20
|
+
<li>level-4
|
21
|
+
<ul>
|
22
|
+
<li>level-5</li>
|
23
|
+
</ul>
|
24
|
+
</li>
|
25
|
+
</ul>
|
26
|
+
</li>
|
27
|
+
</ul>
|
28
|
+
</li>
|
29
|
+
</ul>
|
30
|
+
</li>
|
31
|
+
</ul>
|
32
|
+
HTML
|
33
|
+
|
34
|
+
assert_equal(expected, Kramdown::Document.new(text).to_html)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_kramdown_list_2
|
38
|
+
text = <<-MARKDOWN
|
39
|
+
* level-1
|
40
|
+
* level-3
|
41
|
+
* level-2
|
42
|
+
* level-4
|
43
|
+
* level-5
|
44
|
+
MARKDOWN
|
45
|
+
expected = <<-HTML
|
46
|
+
<ul>
|
47
|
+
<li>level-1
|
48
|
+
<ul>
|
49
|
+
<li>level-3</li>
|
50
|
+
<li>level-2
|
51
|
+
<ul>
|
52
|
+
<li>level-4
|
53
|
+
<ul>
|
54
|
+
<li>level-5</li>
|
55
|
+
</ul>
|
56
|
+
</li>
|
57
|
+
</ul>
|
58
|
+
</li>
|
59
|
+
</ul>
|
60
|
+
</li>
|
61
|
+
</ul>
|
62
|
+
HTML
|
63
|
+
|
64
|
+
assert_equal(expected, Kramdown::Document.new(text).to_html)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_kramdown_list_3
|
68
|
+
text = <<-MARKDOWN
|
69
|
+
* level-4
|
70
|
+
* level-3
|
71
|
+
* level-2
|
72
|
+
* level-1
|
73
|
+
MARKDOWN
|
74
|
+
expected = <<-HTML
|
75
|
+
HTML
|
76
|
+
|
77
|
+
assert_equal(expected, Kramdown::Document.new(text).to_html)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_kramdown_list_3
|
81
|
+
text = <<-MARKDOWN
|
82
|
+
* level-1
|
83
|
+
* level-4
|
84
|
+
* level-3
|
85
|
+
* level-2
|
86
|
+
* level-1
|
87
|
+
MARKDOWN
|
88
|
+
expected = <<-HTML
|
89
|
+
<ul>
|
90
|
+
<li>level-1
|
91
|
+
* level-4
|
92
|
+
<ul>
|
93
|
+
<li>level-3</li>
|
94
|
+
<li>level-2</li>
|
95
|
+
</ul>
|
96
|
+
</li>
|
97
|
+
<li>level-1</li>
|
98
|
+
</ul>
|
99
|
+
HTML
|
100
|
+
|
101
|
+
assert_equal(expected, Kramdown::Document.new(text).to_html)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_kramdown_list_3
|
105
|
+
text = <<-MARKDOWN
|
106
|
+
* level-1
|
107
|
+
* level-3
|
108
|
+
* level-2
|
109
|
+
* level-1
|
110
|
+
MARKDOWN
|
111
|
+
expected = <<-HTML
|
112
|
+
<ul>
|
113
|
+
<li>level-1
|
114
|
+
<ul>
|
115
|
+
<li>level-3</li>
|
116
|
+
<li>level-2</li>
|
117
|
+
</ul>
|
118
|
+
</li>
|
119
|
+
<li>level-1</li>
|
120
|
+
</ul>
|
121
|
+
HTML
|
122
|
+
|
123
|
+
assert_equal(expected, Kramdown::Document.new(text).to_html)
|
124
|
+
end
|
125
|
+
end
|
@@ -23,10 +23,18 @@ class TestVariousTocHtml < Minitest::Test
|
|
23
23
|
<h1>h1</h1>
|
24
24
|
HTML
|
25
25
|
|
26
|
+
TEST_HTML_4 = <<-HTML
|
27
|
+
<h1>h1</h1>
|
28
|
+
<h3>h3</h3>
|
29
|
+
<h2>h2</h2>
|
30
|
+
<h4>h4</h4>
|
31
|
+
<h5>h5</h5>
|
32
|
+
HTML
|
33
|
+
|
26
34
|
def test_nested_toc
|
27
|
-
|
28
|
-
doc = Nokogiri::HTML(
|
29
|
-
|
35
|
+
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
|
36
|
+
doc = Nokogiri::HTML(parser.toc)
|
37
|
+
expected = <<-HTML
|
30
38
|
<ul class="section-nav">
|
31
39
|
<li class="toc-entry toc-h1">
|
32
40
|
<a href="#h1">h1</a>
|
@@ -41,20 +49,19 @@ class TestVariousTocHtml < Minitest::Test
|
|
41
49
|
</li>
|
42
50
|
</ul>
|
43
51
|
HTML
|
44
|
-
|
52
|
+
|
53
|
+
assert_equal(expected, doc.css('ul.section-nav').to_s)
|
45
54
|
end
|
46
55
|
|
47
56
|
def test_complex_nested_toc
|
48
|
-
|
49
|
-
doc = Nokogiri::HTML(
|
50
|
-
|
57
|
+
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_2)
|
58
|
+
doc = Nokogiri::HTML(parser.toc)
|
59
|
+
expected = <<-HTML
|
51
60
|
<ul class="section-nav">
|
52
61
|
<li class="toc-entry toc-h1">
|
53
62
|
<a href="#h1">h1</a>
|
54
63
|
<ul>
|
55
|
-
<ul>
|
56
64
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
57
|
-
</ul>
|
58
65
|
<li class="toc-entry toc-h2">
|
59
66
|
<a href="#h2">h2</a>
|
60
67
|
<ul>
|
@@ -65,32 +72,53 @@ class TestVariousTocHtml < Minitest::Test
|
|
65
72
|
</li>
|
66
73
|
</ul>
|
67
74
|
HTML
|
68
|
-
|
75
|
+
|
76
|
+
assert_equal(expected, doc.css('ul.section-nav').to_s)
|
69
77
|
end
|
70
78
|
|
71
79
|
def test_decremental_headings
|
72
|
-
|
73
|
-
doc = Nokogiri::HTML(
|
74
|
-
|
80
|
+
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_3)
|
81
|
+
doc = Nokogiri::HTML(parser.toc)
|
82
|
+
expected = <<-HTML
|
75
83
|
<ul class="section-nav">
|
76
|
-
<ul>
|
77
|
-
<ul>
|
78
|
-
<ul>
|
79
|
-
<ul>
|
80
|
-
<ul>
|
81
84
|
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
82
|
-
</ul>
|
83
85
|
<li class="toc-entry toc-h5"><a href="#h5">h5</a></li>
|
84
|
-
</ul>
|
85
86
|
<li class="toc-entry toc-h4"><a href="#h4">h4</a></li>
|
87
|
+
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
88
|
+
<li class="toc-entry toc-h2"><a href="#h2">h2</a></li>
|
89
|
+
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
86
90
|
</ul>
|
91
|
+
HTML
|
92
|
+
|
93
|
+
assert_equal(expected, doc.css('ul.section-nav').to_s)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def test_decremental_headings
|
98
|
+
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_4)
|
99
|
+
doc = Nokogiri::HTML(parser.toc)
|
100
|
+
expected = <<-HTML
|
101
|
+
<ul class="section-nav">
|
102
|
+
<li class="toc-entry toc-h1">
|
103
|
+
<a href="#h1">h1</a>
|
104
|
+
<ul>
|
87
105
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
106
|
+
<li class="toc-entry toc-h2">
|
107
|
+
<a href="#h2">h2</a>
|
108
|
+
<ul>
|
109
|
+
<li class="toc-entry toc-h4">
|
110
|
+
<a href="#h4">h4</a>
|
111
|
+
<ul>
|
112
|
+
<li class="toc-entry toc-h5"><a href="#h5">h5</a></li>
|
88
113
|
</ul>
|
89
|
-
|
114
|
+
</li>
|
90
115
|
</ul>
|
91
|
-
|
116
|
+
</li>
|
117
|
+
</ul>
|
118
|
+
</li>
|
92
119
|
</ul>
|
93
120
|
HTML
|
94
|
-
|
121
|
+
|
122
|
+
assert_equal(expected, doc.css('ul.section-nav').to_s)
|
95
123
|
end
|
96
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.
|
4
|
+
version: 0.4.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshimaru
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-10-
|
12
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/version.rb
|
137
137
|
- test/test_helper.rb
|
138
138
|
- test/test_inject_anchors_filter.rb
|
139
|
+
- test/test_kramdown_list.rb
|
139
140
|
- test/test_toc_filter.rb
|
140
141
|
- test/test_toc_only_filter.rb
|
141
142
|
- test/test_various_toc_html.rb
|
@@ -143,10 +144,7 @@ homepage: https://github.com/toshimaru/jekyll-toc
|
|
143
144
|
licenses:
|
144
145
|
- MIT
|
145
146
|
metadata: {}
|
146
|
-
post_install_message:
|
147
|
-
As of jekyll-toc 0.3, nested toc is supported! Please make sure your toc is not broken after update jekyll-toc.
|
148
|
-
|
149
|
-
For more info: https://github.com/toshimaru/jekyll-toc/wiki/0.3-Upgrade-Guide
|
147
|
+
post_install_message:
|
150
148
|
rdoc_options: []
|
151
149
|
require_paths:
|
152
150
|
- lib
|
@@ -169,6 +167,7 @@ summary: Jekyll Table of Contents plugin
|
|
169
167
|
test_files:
|
170
168
|
- test/test_helper.rb
|
171
169
|
- test/test_inject_anchors_filter.rb
|
170
|
+
- test/test_kramdown_list.rb
|
172
171
|
- test/test_toc_filter.rb
|
173
172
|
- test/test_toc_only_filter.rb
|
174
173
|
- test/test_various_toc_html.rb
|