jekyll-toc 0.15.0 → 0.16.0
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/.github/workflows/coverage.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/Gemfile +1 -0
- data/README.md +9 -11
- data/lib/table_of_contents/configuration.rb +3 -1
- data/lib/table_of_contents/parser.rb +1 -1
- data/lib/table_of_contents/version.rb +1 -1
- data/test/parser/test_inject_anchors_filter.rb +1 -1
- data/test/parser/test_invalid_options.rb +1 -1
- data/test/parser/test_ordered_list.rb +2 -2
- data/test/parser/test_toc_filter.rb +1 -1
- data/test/parser/test_toc_only_filter.rb +1 -1
- data/test/parser/test_various_toc_html.rb +16 -16
- data/test/test_configuration.rb +2 -0
- data/test/test_jekyll-toc.rb +2 -2
- data/test/test_kramdown_list.rb +5 -5
- data/test/test_toc_tag.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7b0687350d7dfb3589aa9f476f4b2e937aa03dfa7469443ccf7c81eb66557b
|
4
|
+
data.tar.gz: 7318efc6eb7aaf665f74bbae9ae48c26d46f684b54ac36381bd19905e3413f00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c7862b108fcd48e8483945ed8fd0354d9e3f255a6f1c564607da167b1dfde6c59996c3934987c1a2542e36112bb1ad34fcc83b0de6bed65d524b9b7afd05dc5
|
7
|
+
data.tar.gz: e892d4e54cd93a74ae82838cfe451c4b6a9936362ed02cef7552eae7012395091cf3164370dc7c7b9e5a37921ad990b69b128d8640aa5a35795ffb7a714a8301
|
@@ -4,7 +4,7 @@ jobs:
|
|
4
4
|
build:
|
5
5
|
strategy:
|
6
6
|
matrix:
|
7
|
-
ruby: [2.
|
7
|
+
ruby: [2.7]
|
8
8
|
runs-on: ubuntu-latest
|
9
9
|
name: coverage
|
10
10
|
steps:
|
@@ -15,7 +15,7 @@ jobs:
|
|
15
15
|
ruby-version: ${{ matrix.ruby }}
|
16
16
|
- name: bundle install
|
17
17
|
run: bundle install --jobs 4 --retry 3
|
18
|
-
- uses: paambaati/codeclimate-action@v2.7.
|
18
|
+
- uses: paambaati/codeclimate-action@v2.7.5
|
19
19
|
env:
|
20
20
|
CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
|
21
21
|
with:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
- [Skip TOC](#skip-toc)
|
20
20
|
- [Skip TOC Sectionally](#skip-toc-sectionally)
|
21
21
|
- [CSS Styling](#css-styling)
|
22
|
-
- [Custom CSS Class](#custom-css-class)
|
22
|
+
- [Custom CSS Class and ID](#custom-css-class-and-id)
|
23
23
|
- [Using Unordered/Ordered lists](#using-unorderedordered-lists)
|
24
24
|
- [Alternative Tools](#alternative-tools)
|
25
25
|
|
@@ -121,7 +121,7 @@ location with the `toc_only` filter.
|
|
121
121
|
jekyll-toc generates an unordered list by default. The HTML output is as follows.
|
122
122
|
|
123
123
|
```html
|
124
|
-
<ul class="section-nav">
|
124
|
+
<ul id="toc" class="section-nav">
|
125
125
|
<li class="toc-entry toc-h1"><a href="#heading1">Heading.1</a>
|
126
126
|
<ul>
|
127
127
|
<li class="toc-entry toc-h2"><a href="#heading1-1">Heading.1-1</a></li>
|
@@ -157,6 +157,7 @@ toc:
|
|
157
157
|
max_level: 6
|
158
158
|
ordered_list: false
|
159
159
|
no_toc_section_class: no_toc_section
|
160
|
+
list_id: toc
|
160
161
|
list_class: section-nav
|
161
162
|
sublist_class: ''
|
162
163
|
item_class: toc-entry
|
@@ -252,21 +253,18 @@ Each TOC `li` entry has two CSS classes for further styling. The general `toc-en
|
|
252
253
|
Depending on the heading level each specific entry refers to, it has a second CSS class `toc-XX`, where `XX` is the HTML heading tag name.
|
253
254
|
For example, the TOC entry linking to a heading `<h1>...</h1>` (a single `#` in Markdown) will get the CSS class `toc-h1`.
|
254
255
|
|
255
|
-
### Custom CSS Class
|
256
|
+
### Custom CSS Class and ID
|
256
257
|
|
257
258
|
You can apply custom CSS classes to the generated `<ul>` and `<li>` tags.
|
258
259
|
|
259
260
|
```yml
|
260
261
|
# _config.yml
|
261
262
|
toc:
|
262
|
-
# Default
|
263
|
-
list_class: my-list-class
|
264
|
-
# Default
|
265
|
-
|
266
|
-
# Default
|
267
|
-
item_class: my-item-class
|
268
|
-
# Default is "toc-":
|
269
|
-
item_prefix: item-
|
263
|
+
list_id: my-toc-id # Default: "toc"
|
264
|
+
list_class: my-list-class # Default: "section-nav"
|
265
|
+
sublist_class: my-sublist-class # Default: no class for sublists
|
266
|
+
item_class: my-item-class # Default: "toc-entry"
|
267
|
+
item_prefix: item- # Default: "toc-":
|
270
268
|
```
|
271
269
|
|
272
270
|
### Using Unordered/Ordered lists
|
@@ -5,13 +5,14 @@ module Jekyll
|
|
5
5
|
# jekyll-toc configuration class
|
6
6
|
class Configuration
|
7
7
|
attr_reader :toc_levels, :no_toc_class, :ordered_list, :no_toc_section_class,
|
8
|
-
:list_class, :sublist_class, :item_class, :item_prefix
|
8
|
+
:list_id, :list_class, :sublist_class, :item_class, :item_prefix
|
9
9
|
|
10
10
|
DEFAULT_CONFIG = {
|
11
11
|
'min_level' => 1,
|
12
12
|
'max_level' => 6,
|
13
13
|
'ordered_list' => false,
|
14
14
|
'no_toc_section_class' => 'no_toc_section',
|
15
|
+
'list_id' => 'toc',
|
15
16
|
'list_class' => 'section-nav',
|
16
17
|
'sublist_class' => '',
|
17
18
|
'item_class' => 'toc-entry',
|
@@ -25,6 +26,7 @@ module Jekyll
|
|
25
26
|
@ordered_list = options['ordered_list']
|
26
27
|
@no_toc_class = 'no_toc'
|
27
28
|
@no_toc_section_class = options['no_toc_section_class']
|
29
|
+
@list_id = options['list_id']
|
28
30
|
@list_class = options['list_class']
|
29
31
|
@sublist_class = options['sublist_class']
|
30
32
|
@item_class = options['item_class']
|
@@ -19,7 +19,7 @@ module Jekyll
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def build_toc
|
22
|
-
%(<#{list_tag} class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}</#{list_tag}>)
|
22
|
+
%(<#{list_tag} id="#{@configuration.list_id}" class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}</#{list_tag}>)
|
23
23
|
end
|
24
24
|
|
25
25
|
def inject_anchors_into_html
|
@@ -27,7 +27,7 @@ class TestOrderedList < Minitest::Test
|
|
27
27
|
parse_with_ordered_list
|
28
28
|
html = @parser.toc
|
29
29
|
|
30
|
-
assert_match(/^<ol class="section-nav">/, html)
|
30
|
+
assert_match(/^<ol id="toc" class="section-nav">/, html)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_ordered_list_sub_headings
|
@@ -41,7 +41,7 @@ class TestOrderedList < Minitest::Test
|
|
41
41
|
parse_with_ordered_list_and_classes
|
42
42
|
html = @parser.toc
|
43
43
|
|
44
|
-
assert_match(/^<ol class="top-list-class">/, html)
|
44
|
+
assert_match(/^<ol id="toc" class="top-list-class">/, html)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_ordered_list_sub_headings_with_classes
|
@@ -12,7 +12,7 @@ class TestTOCOnlyFilter < Minitest::Test
|
|
12
12
|
def test_injects_toc_container
|
13
13
|
html = @parser.build_toc
|
14
14
|
|
15
|
-
assert_includes(html, %(<ul class="section-nav">))
|
15
|
+
assert_includes(html, %(<ul id="toc" class="section-nav">))
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_does_not_return_content
|
@@ -12,7 +12,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
12
12
|
def test_nested_toc
|
13
13
|
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML)
|
14
14
|
expected = <<~HTML.chomp
|
15
|
-
<ul class="section-nav">
|
15
|
+
<ul id="toc" class="section-nav">
|
16
16
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
17
17
|
<ul>
|
18
18
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
@@ -31,7 +31,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
31
31
|
def test_nested_toc_with_min_and_max
|
32
32
|
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML, 'min_level' => 2, 'max_level' => 5)
|
33
33
|
expected = <<~HTML.chomp
|
34
|
-
<ul class="section-nav">
|
34
|
+
<ul id="toc" class="section-nav">
|
35
35
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
36
36
|
</ul>
|
37
37
|
HTML
|
@@ -47,7 +47,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
47
47
|
<h6>h6</h6>
|
48
48
|
HTML
|
49
49
|
expected = <<~HTML.chomp
|
50
|
-
<ul class="section-nav">
|
50
|
+
<ul id="toc" class="section-nav">
|
51
51
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
52
52
|
<ul>
|
53
53
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
@@ -74,7 +74,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
74
74
|
<h1>h1</h1>
|
75
75
|
HTML
|
76
76
|
expected = <<~HTML.chomp
|
77
|
-
<ul class="section-nav">
|
77
|
+
<ul id="toc" class="section-nav">
|
78
78
|
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
79
79
|
<li class="toc-entry toc-h5"><a href="#h5">h5</a></li>
|
80
80
|
<li class="toc-entry toc-h4"><a href="#h4">h4</a></li>
|
@@ -96,7 +96,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
96
96
|
<h5>h5</h5>
|
97
97
|
HTML
|
98
98
|
expected = <<~HTML.chomp
|
99
|
-
<ul class="section-nav">
|
99
|
+
<ul id="toc" class="section-nav">
|
100
100
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
101
101
|
<ul>
|
102
102
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
@@ -129,7 +129,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
129
129
|
<h4 class="no_toc">no_toc h4</h4>
|
130
130
|
HTML
|
131
131
|
expected = <<~HTML.chomp
|
132
|
-
<ul class="section-nav">
|
132
|
+
<ul id="toc" class="section-nav">
|
133
133
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
134
134
|
<ul>
|
135
135
|
<li class="toc-entry toc-h2"><a href="#h2">h2</a>
|
@@ -156,7 +156,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
156
156
|
<h3>う</h3>
|
157
157
|
HTML
|
158
158
|
expected = <<~HTML.chomp
|
159
|
-
<ul class="section-nav">
|
159
|
+
<ul id="toc" class="section-nav">
|
160
160
|
<li class="toc-entry toc-h1"><a href="#%E3%81%82">あ</a>
|
161
161
|
<ul>
|
162
162
|
<li class="toc-entry toc-h2"><a href="#%E3%81%84">い</a>
|
@@ -184,7 +184,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
184
184
|
<h1>& < ></h1>
|
185
185
|
HTML
|
186
186
|
expected = <<~HTML.chomp
|
187
|
-
<ul class="section-nav">
|
187
|
+
<ul id="toc" class="section-nav">
|
188
188
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
189
189
|
<li class="toc-entry toc-h1"><a href="#base-href"><base href></a></li>
|
190
190
|
<li class="toc-entry toc-h1"><a href="#--">& < ></a></li>
|
@@ -200,7 +200,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
200
200
|
<h2><em>h2</em></h2>
|
201
201
|
HTML
|
202
202
|
expected = <<~HTML.chomp
|
203
|
-
<ul class="section-nav">
|
203
|
+
<ul id="toc" class="section-nav">
|
204
204
|
<li class="toc-entry toc-h2"><a href="#h2">h2</a></li>
|
205
205
|
<li class="toc-entry toc-h2"><a href="#h2-1">h2</a></li>
|
206
206
|
</ul>
|
@@ -219,7 +219,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
219
219
|
<h6>h6</h6>
|
220
220
|
HTML
|
221
221
|
expected = <<~HTML.chomp
|
222
|
-
<ul class="section-nav">
|
222
|
+
<ul id="toc" class="section-nav">
|
223
223
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
224
224
|
<ul>
|
225
225
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
@@ -254,7 +254,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
254
254
|
<h6>h6</h6>
|
255
255
|
HTML
|
256
256
|
expected = <<~HTML.chomp
|
257
|
-
<ul class="section-nav">
|
257
|
+
<ul id="toc" class="section-nav">
|
258
258
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
259
259
|
<ul>
|
260
260
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
@@ -291,7 +291,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
291
291
|
<h6>h6</h6>
|
292
292
|
HTML
|
293
293
|
expected = <<~HTML.chomp
|
294
|
-
<ul class="section-nav">
|
294
|
+
<ul id="toc" class="section-nav">
|
295
295
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
296
296
|
<ul>
|
297
297
|
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
@@ -321,7 +321,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
321
321
|
<h1 id="third">h3</h1>
|
322
322
|
HTML
|
323
323
|
expected = <<~HTML.chomp
|
324
|
-
<ul class="section-nav">
|
324
|
+
<ul id="toc" class="section-nav">
|
325
325
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
326
326
|
<li class="toc-entry toc-h1"><a href="#second">h2</a></li>
|
327
327
|
<li class="toc-entry toc-h1"><a href="#third">h3</a></li>
|
@@ -342,7 +342,7 @@ class TestVariousTocHtml < Minitest::Test
|
|
342
342
|
<h1>h1</h1>
|
343
343
|
HTML
|
344
344
|
expected = <<~HTML.chomp
|
345
|
-
<ul class="section-nav">
|
345
|
+
<ul id="toc" class="section-nav">
|
346
346
|
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
347
347
|
<li class="toc-entry toc-h1"><a href="#h1-1">h1</a></li>
|
348
348
|
<li class="toc-entry toc-h1"><a href="#h1-2">h1</a></li>
|
@@ -355,10 +355,10 @@ class TestVariousTocHtml < Minitest::Test
|
|
355
355
|
def test_custom_css_classes
|
356
356
|
parser = Jekyll::TableOfContents::Parser.new(
|
357
357
|
TEST_HTML,
|
358
|
-
'item_class' => 'custom-item', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
|
358
|
+
'item_class' => 'custom-item', 'list_id' => 'custom-toc-id', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
|
359
359
|
)
|
360
360
|
expected = <<~HTML.chomp
|
361
|
-
<ul class="custom-list">
|
361
|
+
<ul id="custom-toc-id" class="custom-list">
|
362
362
|
<li class="custom-item custom-prefix-h1"><a href="#h1">h1</a>
|
363
363
|
<ul class="custom-sublist">
|
364
364
|
<li class="custom-item custom-prefix-h3"><a href="#h3">h3</a>
|
data/test/test_configuration.rb
CHANGED
@@ -9,6 +9,7 @@ class TestConfiguration < Minitest::Test
|
|
9
9
|
assert_equal(1..6, configuration.toc_levels)
|
10
10
|
refute(configuration.ordered_list)
|
11
11
|
assert_equal('no_toc_section', configuration.no_toc_section_class)
|
12
|
+
assert_equal('toc', configuration.list_id)
|
12
13
|
assert_equal('section-nav', configuration.list_class)
|
13
14
|
assert_equal('', configuration.sublist_class)
|
14
15
|
assert_equal('toc-entry', configuration.item_class)
|
@@ -21,6 +22,7 @@ class TestConfiguration < Minitest::Test
|
|
21
22
|
assert_equal(1..6, configuration.toc_levels)
|
22
23
|
refute(configuration.ordered_list)
|
23
24
|
assert_equal('no_toc_section', configuration.no_toc_section_class)
|
25
|
+
assert_equal('toc', configuration.list_id)
|
24
26
|
assert_equal('section-nav', configuration.list_class)
|
25
27
|
assert_equal('', configuration.sublist_class)
|
26
28
|
assert_equal('toc-entry', configuration.item_class)
|
data/test/test_jekyll-toc.rb
CHANGED
@@ -24,7 +24,7 @@ class TestTableOfContentsFilter < Minitest::Test
|
|
24
24
|
|
25
25
|
def test_toc_only2
|
26
26
|
@context = enable_toc_context
|
27
|
-
assert_equal
|
27
|
+
assert_equal %(<ul id="toc" class="section-nav">\n</ul>), toc_only(DUMMY_HTML)
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_inject_anchors2
|
@@ -34,7 +34,7 @@ class TestTableOfContentsFilter < Minitest::Test
|
|
34
34
|
|
35
35
|
def test_toc2
|
36
36
|
@context = enable_toc_context
|
37
|
-
assert_equal
|
37
|
+
assert_equal %(<ul id="toc" class="section-nav">\n</ul>#{DUMMY_HTML}), toc(DUMMY_HTML)
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
data/test/test_kramdown_list.rb
CHANGED
@@ -36,7 +36,7 @@ class TestKramdownList < Minitest::Test
|
|
36
36
|
assert_equal(expected, actual)
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def test_kramdown_list_l1_l5
|
40
40
|
text = <<~MARKDOWN
|
41
41
|
* level-1
|
42
42
|
* level-2
|
@@ -70,7 +70,7 @@ class TestKramdownList < Minitest::Test
|
|
70
70
|
assert_equal(expected, actual)
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
73
|
+
def test_kramdown_list_l1_l3_l2_l4
|
74
74
|
text = <<~MARKDOWN
|
75
75
|
* level-1
|
76
76
|
* level-3
|
@@ -101,7 +101,7 @@ class TestKramdownList < Minitest::Test
|
|
101
101
|
assert_equal(expected, actual)
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
104
|
+
def test_kramdown_list_l4_l1
|
105
105
|
text = <<~MARKDOWN
|
106
106
|
* level-4
|
107
107
|
* level-3
|
@@ -118,7 +118,7 @@ class TestKramdownList < Minitest::Test
|
|
118
118
|
assert_equal(expected, actual)
|
119
119
|
end
|
120
120
|
|
121
|
-
def
|
121
|
+
def test_kramdown_list_l1_l4_l1
|
122
122
|
text = <<~MARKDOWN
|
123
123
|
* level-1
|
124
124
|
* level-4
|
@@ -143,7 +143,7 @@ class TestKramdownList < Minitest::Test
|
|
143
143
|
assert_equal(expected, actual)
|
144
144
|
end
|
145
145
|
|
146
|
-
def
|
146
|
+
def test_kramdown_list_l1_l3_l1
|
147
147
|
text = <<~MARKDOWN
|
148
148
|
* level-1
|
149
149
|
* level-3
|
data/test/test_toc_tag.rb
CHANGED
@@ -17,7 +17,7 @@ class TestTableOfContentsTag < Minitest::Test
|
|
17
17
|
site: @stubbed_context1.new({ 'toc' => nil })
|
18
18
|
)
|
19
19
|
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
|
20
|
-
assert_equal(
|
20
|
+
assert_equal(%(<ul id="toc" class="section-nav">\n<li class="toc-entry toc-h1"><a href="#test">test</a></li>\n</ul>), tag.render(context))
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_toc_tag_returns_empty_string
|
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.16.0
|
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: 2020-
|
12
|
+
date: 2020-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|