jekyll-toc 0.7.1 → 0.8.0.beta1
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.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/table_of_contents/parser.rb +6 -1
- data/lib/version.rb +1 -1
- data/test/test_various_toc_html.rb +36 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d596d99053aad35a05c81278de0edfad519bd76727ff60d9b01b70e71008e987
|
4
|
+
data.tar.gz: 331da3befd626489ff0a39d9d70837abbd902bf8cb17548b219b10e7e24b876a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2c4e4cba02a4205b05249997746a4acab870876e89368b54f601e0082908e42ea3e08098483b3e12b0eb691cbf24a60da81c86db8717525336486d1deb083c
|
7
|
+
data.tar.gz: 577d24958e189a1f69feafb48e8f1a937cfdbb966ba5186773fe693641bd958575145186dc7d5e7d13be26b633437a06146d9c73c179c46ecbc5065568a57e7e
|
data/README.md
CHANGED
@@ -133,6 +133,26 @@ toc:
|
|
133
133
|
|
134
134
|
The default level range is `<h1>` to `<h6>`.
|
135
135
|
|
136
|
+
### Ignore within
|
137
|
+
|
138
|
+
It can be configured to ignore elements within a selector:
|
139
|
+
|
140
|
+
```yml
|
141
|
+
toc:
|
142
|
+
ignore_within: .exclude
|
143
|
+
```
|
144
|
+
|
145
|
+
```html
|
146
|
+
<h1>h1</h1>
|
147
|
+
<div class="exclude">
|
148
|
+
<h2>h2</h2>
|
149
|
+
<h3>h3</h3>
|
150
|
+
</div>
|
151
|
+
<h4>h4</h4>
|
152
|
+
```
|
153
|
+
|
154
|
+
Which would result in only the `<h1>` & `<h4>` within the example being included in the TOC.
|
155
|
+
|
136
156
|
### CSS Styling
|
137
157
|
|
138
158
|
The toc can be modified with CSS. The sample CSS is the following.
|
@@ -14,7 +14,8 @@ module Jekyll
|
|
14
14
|
def initialize(html, options = {})
|
15
15
|
@doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
16
16
|
options = generate_option_hash(options)
|
17
|
-
@toc_levels = options[
|
17
|
+
@toc_levels = options["min_level"]..options["max_level"]
|
18
|
+
@ignore_within = options["ignore_within"]
|
18
19
|
@entries = parse_content
|
19
20
|
end
|
20
21
|
|
@@ -42,6 +43,10 @@ module Jekyll
|
|
42
43
|
entries = []
|
43
44
|
headers = Hash.new(0)
|
44
45
|
|
46
|
+
if @ignore_within
|
47
|
+
@doc.css(@ignore_within).remove
|
48
|
+
end
|
49
|
+
|
45
50
|
# TODO: Use kramdown auto ids
|
46
51
|
@doc.css(toc_headings).reject { |n| n.classes.include?('no_toc') }.each do |node|
|
47
52
|
text = node.text
|
data/lib/version.rb
CHANGED
@@ -245,6 +245,42 @@ class TestVariousTocHtml < Minitest::Test
|
|
245
245
|
HTML
|
246
246
|
actual = doc.css('ul.section-nav').to_s
|
247
247
|
|
248
|
+
assert_equal(expected, actual)
|
249
|
+
end
|
250
|
+
|
251
|
+
TEST_HTML_IGNORE = <<-HTML
|
252
|
+
<h1>h1</h1>
|
253
|
+
<div class="exclude">
|
254
|
+
<h2>h2</h2>
|
255
|
+
</div>
|
256
|
+
<h3>h3</h3>
|
257
|
+
<div class="exclude">
|
258
|
+
<h4>h4</h4>
|
259
|
+
<h4>h5</h4>
|
260
|
+
</div>
|
261
|
+
<h6>h6</h6>
|
262
|
+
HTML
|
263
|
+
|
264
|
+
def test_nested_toc_with_ignore_within_option
|
265
|
+
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE, { "ignore_within" => '.exclude'})
|
266
|
+
doc = Nokogiri::HTML(parser.toc)
|
267
|
+
expected = <<-HTML
|
268
|
+
<ul class="section-nav">
|
269
|
+
<li class="toc-entry toc-h1">
|
270
|
+
<a href="#h1">h1</a>
|
271
|
+
<ul>
|
272
|
+
<li class="toc-entry toc-h3">
|
273
|
+
<a href="#h3">h3</a>
|
274
|
+
<ul>
|
275
|
+
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
276
|
+
</ul>
|
277
|
+
</li>
|
278
|
+
</ul>
|
279
|
+
</li>
|
280
|
+
</ul>
|
281
|
+
HTML
|
282
|
+
actual = doc.css('ul.section-nav').to_s
|
283
|
+
|
248
284
|
assert_equal(expected, actual)
|
249
285
|
end
|
250
286
|
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
|
+
version: 0.8.0.beta1
|
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: 2018-09
|
12
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -153,9 +153,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: 2.2.2
|
154
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - ">"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 1.3.1
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
161
|
rubygems_version: 2.7.6
|