jekyll-toc 0.15.0.rc → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +19 -0
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/coverage.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.rubocop.yml +4 -0
- data/Gemfile +3 -1
- data/README.md +53 -23
- data/jekyll-toc.gemspec +2 -2
- data/lib/table_of_contents/version.rb +1 -1
- data/test/parser/test_inject_anchors_filter.rb +1 -1
- data/test/parser/test_ordered_list.rb +4 -4
- data/test/parser/test_toc_only_filter.rb +2 -2
- data/test/test_configuration.rb +14 -14
- data/test/test_toc_tag.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e250bc0a38525c4496ba464685b2ca3bc9c462953ce7c299a52cf52611940099
|
4
|
+
data.tar.gz: 628f832e2adaae7b8b225423149b6dd950d04c884698f1b8e42c6e3990f33359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 258fde765cb95ce75abd2b87a4336a3a58630188e872c337014b8b780ac06843521b49070a201a3c9cdc7530409f61caeb159b770801b580eed8fb4921a5f74c
|
7
|
+
data.tar.gz: d9d8e1dc2b78c353333db1af1ad03eb86b387e35e89fea8fd554c834e3b8d93b200539f48f9bc070d95bb24f18addb8127329b966a6512ef6bac02909ce37ef1
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "bundler"
|
9
|
+
directory: "/"
|
10
|
+
schedule:
|
11
|
+
interval: "weekly"
|
12
|
+
reviewers:
|
13
|
+
- toshimaru
|
14
|
+
- package-ecosystem: "github-actions"
|
15
|
+
directory: "/"
|
16
|
+
schedule:
|
17
|
+
interval: "weekly"
|
18
|
+
reviewers:
|
19
|
+
- toshimaru
|
data/.github/workflows/ci.yml
CHANGED
@@ -10,12 +10,12 @@ jobs:
|
|
10
10
|
steps:
|
11
11
|
- uses: actions/checkout@v2
|
12
12
|
- name: Set up Ruby ${{ matrix.ruby }}
|
13
|
-
uses:
|
13
|
+
uses: actions/setup-ruby@v1
|
14
14
|
with:
|
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.4
|
18
|
+
- uses: paambaati/codeclimate-action@v2.7.4
|
19
19
|
env:
|
20
20
|
CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
|
21
21
|
with:
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,17 +9,19 @@
|
|
9
9
|
|
10
10
|
- [Installation](#installation)
|
11
11
|
- [Usage](#usage)
|
12
|
-
- [
|
13
|
-
- [
|
12
|
+
- [Basic Usage](#basic-usage)
|
13
|
+
- [Advanced Usage](#advanced-usage)
|
14
14
|
- [Generated HTML](#generated-html)
|
15
|
-
- [Default Configuration](#default-configuration)
|
16
15
|
- [Customization](#customization)
|
16
|
+
- [Default Configuration](#default-configuration)
|
17
17
|
- [TOC levels](#toc-levels)
|
18
|
+
- [Enable TOC by default](#enable-toc-by-default)
|
18
19
|
- [Skip TOC](#skip-toc)
|
19
|
-
- [Skip TOC
|
20
|
+
- [Skip TOC Sectionally](#skip-toc-sectionally)
|
20
21
|
- [CSS Styling](#css-styling)
|
21
22
|
- [Custom CSS Class](#custom-css-class)
|
22
23
|
- [Using Unordered/Ordered lists](#using-unorderedordered-lists)
|
24
|
+
- [Alternative Tools](#alternative-tools)
|
23
25
|
|
24
26
|
## Installation
|
25
27
|
|
@@ -51,7 +53,7 @@ toc: true
|
|
51
53
|
There are three Liquid filters, which can be applied to HTML content,
|
52
54
|
e.g. the Liquid variable `content` available in Jekyll's templates.
|
53
55
|
|
54
|
-
###
|
56
|
+
### Basic Usage
|
55
57
|
|
56
58
|
#### `toc` filter
|
57
59
|
|
@@ -63,11 +65,11 @@ Add the `toc` filter to your site's `{{ content }}` (e.g. `_layouts/post.html`).
|
|
63
65
|
|
64
66
|
This filter places the TOC directly above the content.
|
65
67
|
|
66
|
-
###
|
68
|
+
### Advanced Usage
|
67
69
|
|
68
70
|
If you'd like separated TOC and content, you can use `{% toc %}` tag (or `toc_only` filter) and `inject_anchors` filter.
|
69
71
|
|
70
|
-
#### `{% toc %}` tag
|
72
|
+
#### `{% toc %}` tag / `toc_only` filter
|
71
73
|
|
72
74
|
Generates the TOC itself as described [below](#generated-html).
|
73
75
|
Mostly useful in cases where the TOC should _not_ be placed immediately
|
@@ -86,7 +88,8 @@ above the content but at some other place of the page, i.e. an aside.
|
|
86
88
|
|
87
89
|
:warning: **`{% toc %}` Tag Limitation**
|
88
90
|
|
89
|
-
`{% toc %}`
|
91
|
+
`{% toc %}` works only for [Jekyll Posts](https://jekyllrb.com/docs/step-by-step/08-blogging/) and [Jekyll Collections](https://jekyllrb.com/docs/collections/).
|
92
|
+
If you'd like to use `{% toc %}` except posts or collections, please use `toc_only` filter as described below.
|
90
93
|
|
91
94
|
```html
|
92
95
|
<div>
|
@@ -115,7 +118,7 @@ location with the `toc_only` filter.
|
|
115
118
|
|
116
119
|
## Generated HTML
|
117
120
|
|
118
|
-
jekyll-toc generates an unordered list. The HTML output is as follows.
|
121
|
+
jekyll-toc generates an unordered list by default. The HTML output is as follows.
|
119
122
|
|
120
123
|
```html
|
121
124
|
<ul class="section-nav">
|
@@ -141,9 +144,14 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
|
|
141
144
|
|
142
145
|
![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
|
143
146
|
|
144
|
-
##
|
147
|
+
## Customization
|
148
|
+
|
149
|
+
jekyll-toc is customizable on `_config.yml`.
|
150
|
+
|
151
|
+
### Default Configuration
|
145
152
|
|
146
153
|
```yml
|
154
|
+
# _config.yml
|
147
155
|
toc:
|
148
156
|
min_level: 1
|
149
157
|
max_level: 6
|
@@ -155,39 +163,49 @@ toc:
|
|
155
163
|
item_prefix: toc-
|
156
164
|
```
|
157
165
|
|
158
|
-
## Customization
|
159
|
-
|
160
166
|
### TOC levels
|
161
167
|
|
162
|
-
The toc levels can be configured on `_config.yml`:
|
163
|
-
|
164
168
|
```yml
|
169
|
+
# _config.yml
|
165
170
|
toc:
|
166
171
|
min_level: 2 # default: 1
|
167
172
|
max_level: 5 # default: 6
|
168
173
|
```
|
169
174
|
|
170
|
-
The default
|
175
|
+
The default heading range is from `<h1>` to `<h6>`.
|
176
|
+
|
177
|
+
### Enable TOC by default
|
178
|
+
|
179
|
+
You can enable TOC by default with [Front Matter Defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/):
|
180
|
+
|
181
|
+
```yml
|
182
|
+
# _config.yml
|
183
|
+
defaults:
|
184
|
+
- scope:
|
185
|
+
path: ""
|
186
|
+
values:
|
187
|
+
toc: true
|
188
|
+
```
|
171
189
|
|
172
190
|
### Skip TOC
|
173
191
|
|
174
|
-
The heading is ignored in the toc
|
192
|
+
The heading is ignored in the toc by adding `no_toc` class.
|
175
193
|
|
176
194
|
```html
|
177
195
|
<h1>h1</h1>
|
178
|
-
<h1 class="no_toc">This heading is ignored in the
|
196
|
+
<h1 class="no_toc">This heading is ignored in the TOC</h1>
|
179
197
|
<h2>h2</h2>
|
180
198
|
```
|
181
199
|
|
182
|
-
### Skip TOC
|
200
|
+
### Skip TOC Sectionally
|
183
201
|
|
184
202
|
The headings are ignored inside the element which has `no_toc_section` class.
|
185
203
|
|
186
204
|
```html
|
187
205
|
<h1>h1</h1>
|
188
206
|
<div class="no_toc_section">
|
189
|
-
<h2>This heading is ignored in the
|
190
|
-
<h3>This heading is ignored in the
|
207
|
+
<h2>This heading is ignored in the TOC</h2>
|
208
|
+
<h3>This heading is ignored in the TOC</h3>
|
191
209
|
</div>
|
192
210
|
<h4>h4</h4>
|
193
211
|
```
|
@@ -197,13 +215,15 @@ Which would result in only the `<h1>` & `<h4>` within the example being included
|
|
197
215
|
The class can be configured on `_config.yml`:
|
198
216
|
|
199
217
|
```yml
|
218
|
+
# _config.yml
|
200
219
|
toc:
|
201
220
|
no_toc_section_class: exclude # default: no_toc_section
|
202
221
|
```
|
203
222
|
|
204
|
-
Configuring multiple classes
|
223
|
+
Configuring multiple classes are allowed:
|
205
224
|
|
206
225
|
```yml
|
226
|
+
# _config.yml
|
207
227
|
toc:
|
208
228
|
no_toc_section_class:
|
209
229
|
- no_toc_section
|
@@ -229,14 +249,15 @@ The toc can be modified with CSS. The sample CSS is the following.
|
|
229
249
|
|
230
250
|
Each TOC `li` entry has two CSS classes for further styling. The general `toc-entry` is applied to all `li` elements in the `ul.section-nav`.
|
231
251
|
|
232
|
-
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.
|
233
|
-
`#` in Markdown) will get the CSS class `toc-h1`.
|
252
|
+
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
|
+
For example, the TOC entry linking to a heading `<h1>...</h1>` (a single `#` in Markdown) will get the CSS class `toc-h1`.
|
234
254
|
|
235
255
|
### Custom CSS Class
|
236
256
|
|
237
257
|
You can apply custom CSS classes to the generated `<ul>` and `<li>` tags.
|
238
258
|
|
239
259
|
```yml
|
260
|
+
# _config.yml
|
240
261
|
toc:
|
241
262
|
# Default is "section-nav":
|
242
263
|
list_class: my-list-class
|
@@ -254,6 +275,7 @@ By default the table of contents will be generated as an unordered list via `<ul
|
|
254
275
|
This can be configured in `_config.yml`:
|
255
276
|
|
256
277
|
```yml
|
278
|
+
# _config.yml
|
257
279
|
toc:
|
258
280
|
ordered_list: true # default is false
|
259
281
|
```
|
@@ -264,6 +286,7 @@ Add a class to the `sublist_class` configuration to append it to the `ol` tags s
|
|
264
286
|
Example
|
265
287
|
|
266
288
|
```yml
|
289
|
+
# _config.yml
|
267
290
|
toc:
|
268
291
|
ordered_list: true
|
269
292
|
list_class: my-list-class
|
@@ -283,3 +306,10 @@ toc:
|
|
283
306
|
This will produce:
|
284
307
|
|
285
308
|
![screenshot](https://user-images.githubusercontent.com/7675276/85813980-a0ea5a80-b719-11ea-9458-ccf9b86a778b.png)
|
309
|
+
|
310
|
+
## Alternative Tools
|
311
|
+
|
312
|
+
- Adding anchor to headings
|
313
|
+
- [AnchorJS](https://www.bryanbraun.com/anchorjs/)
|
314
|
+
- Generating TOC for kramdown content
|
315
|
+
- [Automatic “Table of Contents” Generation](https://kramdown.gettalong.org/converter/html.html#toc) (See also. [Create Table of Contents in kramdown](https://blog.toshima.ru/2020/05/22/kramdown-toc))
|
data/jekyll-toc.gemspec
CHANGED
@@ -8,13 +8,13 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'jekyll-toc'
|
9
9
|
spec.version = Jekyll::TableOfContents::VERSION
|
10
10
|
spec.summary = 'Jekyll Table of Contents plugin'
|
11
|
-
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a
|
11
|
+
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a Table of Contents for the page.'
|
12
12
|
spec.authors = %w(toshimaru torbjoernk)
|
13
13
|
spec.email = 'me@toshimaru.net'
|
14
14
|
spec.files = `git ls-files -z`.split("\x0")
|
15
15
|
spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
|
16
16
|
spec.license = 'MIT'
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.required_ruby_version = '>= 2.4'
|
@@ -8,19 +8,19 @@ class TestOrderedList < Minitest::Test
|
|
8
8
|
def test_default_configuration
|
9
9
|
configuration = Jekyll::TableOfContents::Configuration.new({})
|
10
10
|
|
11
|
-
|
11
|
+
refute(configuration.ordered_list)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_disabled_ordered_list
|
15
15
|
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => false)
|
16
16
|
|
17
|
-
|
17
|
+
refute(configuration.ordered_list)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_enabled_ordered_list
|
21
21
|
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => true)
|
22
22
|
|
23
|
-
|
23
|
+
assert(configuration.ordered_list)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_basic_ordered_list_top_heading
|
@@ -57,7 +57,7 @@ class TestOrderedList < Minitest::Test
|
|
57
57
|
|
58
58
|
occurrences = html.scan(/<ol class="sublist-class">/).count
|
59
59
|
|
60
|
-
assert_equal occurrences
|
60
|
+
assert_equal(5, occurrences)
|
61
61
|
end
|
62
62
|
|
63
63
|
private
|
@@ -12,12 +12,12 @@ class TestTOCOnlyFilter < Minitest::Test
|
|
12
12
|
def test_injects_toc_container
|
13
13
|
html = @parser.build_toc
|
14
14
|
|
15
|
-
|
15
|
+
assert_includes(html, %(<ul class="section-nav">))
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_does_not_return_content
|
19
19
|
html = @parser.build_toc
|
20
20
|
|
21
|
-
|
21
|
+
refute_includes(html, %(<h1>Simple H1</h1>))
|
22
22
|
end
|
23
23
|
end
|
data/test/test_configuration.rb
CHANGED
@@ -6,24 +6,24 @@ class TestConfiguration < Minitest::Test
|
|
6
6
|
def test_default_configuration
|
7
7
|
configuration = Jekyll::TableOfContents::Configuration.new({})
|
8
8
|
|
9
|
-
assert_equal configuration.toc_levels
|
10
|
-
|
11
|
-
assert_equal configuration.no_toc_section_class
|
12
|
-
assert_equal
|
13
|
-
assert_equal configuration.sublist_class
|
14
|
-
assert_equal
|
15
|
-
assert_equal configuration.item_prefix
|
9
|
+
assert_equal(1..6, configuration.toc_levels)
|
10
|
+
refute(configuration.ordered_list)
|
11
|
+
assert_equal('no_toc_section', configuration.no_toc_section_class)
|
12
|
+
assert_equal('section-nav', configuration.list_class)
|
13
|
+
assert_equal('', configuration.sublist_class)
|
14
|
+
assert_equal('toc-entry', configuration.item_class)
|
15
|
+
assert_equal('toc-', configuration.item_prefix)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_type_error
|
19
19
|
configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
|
20
20
|
|
21
|
-
assert_equal configuration.toc_levels
|
22
|
-
|
23
|
-
assert_equal configuration.no_toc_section_class
|
24
|
-
assert_equal
|
25
|
-
assert_equal configuration.sublist_class
|
26
|
-
assert_equal
|
27
|
-
assert_equal configuration.item_prefix
|
21
|
+
assert_equal(1..6, configuration.toc_levels)
|
22
|
+
refute(configuration.ordered_list)
|
23
|
+
assert_equal('no_toc_section', configuration.no_toc_section_class)
|
24
|
+
assert_equal('section-nav', configuration.list_class)
|
25
|
+
assert_equal('', configuration.sublist_class)
|
26
|
+
assert_equal('toc-entry', configuration.item_class)
|
27
|
+
assert_equal('toc-', configuration.item_prefix)
|
28
28
|
end
|
29
29
|
end
|
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 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.15.0
|
4
|
+
version: 0.15.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-10-
|
12
|
+
date: 2020-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
@@ -39,13 +39,14 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.10'
|
42
|
-
description: Jekyll (Ruby static website generator) plugin which generates a
|
43
|
-
of
|
42
|
+
description: Jekyll (Ruby static website generator) plugin which generates a Table
|
43
|
+
of Contents for the page.
|
44
44
|
email: me@toshimaru.net
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".github/dependabot.yml"
|
49
50
|
- ".github/workflows/ci.yml"
|
50
51
|
- ".github/workflows/coverage.yml"
|
51
52
|
- ".github/workflows/rubocop.yml"
|
@@ -93,9 +94,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '2.4'
|
94
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
96
|
requirements:
|
96
|
-
- - "
|
97
|
+
- - ">="
|
97
98
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
99
|
+
version: '0'
|
99
100
|
requirements: []
|
100
101
|
rubygems_version: 3.1.4
|
101
102
|
signing_key:
|