jekyll-toc 0.14.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc8236ac8c5ff74ef8f7f23fc8b2b2fedbf94cb238a2c20783256d4ca8523909
4
- data.tar.gz: 8b92259b9e2f5345b58ff472a7232121e18fbac6986bda5938c53ff79bc7c501
3
+ metadata.gz: fe363b8051bd23fb22696b5580fcaade629e103d2797cdebdfe071382523719e
4
+ data.tar.gz: 3c4417745d50b56e7d9ea9ac22d3d9b78738113d87d748fe514332c5838bbd47
5
5
  SHA512:
6
- metadata.gz: 70be39d4763e0ca77a39d1ee77e9a743a2bec709181e0ef75214c767ca2605d342ff2f245eec5aa0ac80fc28b78f58eb82c064687023aeedb4411785b5f5dca1
7
- data.tar.gz: 18d1a1d16869dfbbaec20805470ea5e260e5daa2d252f2a751c479ba3457425f2f0b2b36c8794b29bc61f1637466524448d7acf3201d570b545d29e982e11df6
6
+ metadata.gz: b736b83b238cd84e1501a89cd77ae2414d7206ba38c7196e5d117e03ac04d20d5304cef29fcd0cbe28bce49fbf88c4fa46c3109d75fd39c013dfb142685b614d
7
+ data.tar.gz: 9fb3ecf7aad279a24068ee6c9ee1d78dbf7128f02451ef83e575389be9c5d6ba89775977dab540bfa5801a2abb8c97acc281f5b99086eea7c52493d04aa319c3
@@ -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
@@ -1,23 +1,22 @@
1
1
  name: CI
2
- on: [push]
2
+ on: [push, pull_request]
3
3
  jobs:
4
4
  build:
5
5
  strategy:
6
6
  matrix:
7
- ruby: [2.4, 2.5, 2.6, 2.7]
7
+ ruby: [2.5, 2.6, 2.7, 3.0]
8
8
  gemfile:
9
- - gemfiles/jekyll_4.0.gemfile
10
- - gemfiles/jekyll_3.8.gemfile
11
- exclude:
12
- - ruby: 2.4
13
- gemfile: gemfiles/jekyll_4.0.gemfile
9
+ - gemfiles/jekyll_3.9.gemfile
10
+ - gemfiles/jekyll_4.0.gemfile
11
+ - gemfiles/jekyll_4.1.gemfile
12
+ - gemfiles/jekyll_4.2.gemfile
14
13
  env:
15
14
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
16
15
  runs-on: ubuntu-latest
17
16
  steps:
18
17
  - uses: actions/checkout@v2
19
18
  - name: Set up Ruby ${{ matrix.ruby }}
20
- uses: eregon/use-ruby-action@master
19
+ uses: ruby/setup-ruby@v1
21
20
  with:
22
21
  ruby-version: ${{ matrix.ruby }}
23
22
  - name: bundle install
@@ -1,21 +1,21 @@
1
1
  name: Coverage
2
- on: [push]
2
+ on: [push, pull_request]
3
3
  jobs:
4
4
  build:
5
5
  strategy:
6
6
  matrix:
7
- ruby: [2.6]
7
+ ruby: [3.0]
8
8
  runs-on: ubuntu-latest
9
9
  name: coverage
10
10
  steps:
11
11
  - uses: actions/checkout@v2
12
12
  - name: Set up Ruby ${{ matrix.ruby }}
13
- uses: eregon/use-ruby-action@master
13
+ uses: ruby/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.0
18
+ - uses: paambaati/codeclimate-action@v2.7.5
19
19
  env:
20
20
  CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
21
21
  with:
@@ -1,16 +1,16 @@
1
1
  name: RuboCop
2
- on: [push]
2
+ on: [push, pull_request]
3
3
  jobs:
4
4
  build:
5
5
  strategy:
6
6
  matrix:
7
- ruby: [2.6]
7
+ ruby: [3.0]
8
8
  runs-on: ubuntu-latest
9
9
  name: rubocop
10
10
  steps:
11
11
  - uses: actions/checkout@v2
12
12
  - name: Set up Ruby ${{ matrix.ruby }}
13
- uses: eregon/use-ruby-action@master
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
15
  ruby-version: ${{ matrix.ruby }}
16
16
  - name: bundle install
@@ -1,11 +1,15 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.4
3
+ NewCops: enable
3
4
  Exclude:
4
5
  - "*.gemspec"
5
6
  - "gemfiles/*"
6
7
  - "vendor/**/*"
7
8
  - Rakefile
8
9
  - Gemfile
10
+ require:
11
+ - rubocop-performance
12
+ - rubocop-minitest
9
13
 
10
14
  Metrics/MethodLength:
11
15
  Enabled: false
data/Appraisals CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'jekyll-4.0' do
4
- gem 'jekyll', '4.0'
5
- end
3
+ SUPPORTED_VERSIONS = %w[3.8 3.9 4.0 4.1 4.2].freeze
6
4
 
7
- appraise 'jekyll-3.8' do
8
- gem 'jekyll', '3.8'
5
+ SUPPORTED_VERSIONS.each do |version|
6
+ appraise "jekyll-#{version}" do
7
+ gem 'jekyll', version
8
+ end
9
9
  end
data/Gemfile CHANGED
@@ -7,5 +7,8 @@ gem 'minitest-reporters'
7
7
  gem 'minitest'
8
8
  gem 'pry'
9
9
  gem 'rake'
10
- gem 'rubocop', '~> 0.81'
10
+ gem 'rubocop-minitest'
11
+ gem 'rubocop-performance'
12
+ gem 'rubocop-rake'
13
+ gem 'rubocop'
11
14
  gem 'simplecov', '~> 0.17.1'
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # jekyll-toc
2
2
 
3
3
  ![CI](https://github.com/toshimaru/jekyll-toc/workflows/CI/badge.svg)
4
- [![Gem Version](https://badge.fury.io/rb/jekyll-toc.svg)](http://badge.fury.io/rb/jekyll-toc)
4
+ [![Gem Version](https://badge.fury.io/rb/jekyll-toc.svg)](https://badge.fury.io/rb/jekyll-toc)
5
5
  [![Code Climate](https://codeclimate.com/github/toshimaru/jekyll-toc/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/jekyll-toc)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/toshimaru/jekyll-toc/test_coverage)
7
7
 
@@ -9,16 +9,19 @@
9
9
 
10
10
  - [Installation](#installation)
11
11
  - [Usage](#usage)
12
- - [1. Basic Usage](#1-basic-usage)
13
- - [2. Advanced Usage](#2-advanced-usage)
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 Section](#skip-toc-section)
20
+ - [Skip TOC Sectionally](#skip-toc-sectionally)
20
21
  - [CSS Styling](#css-styling)
21
- - [Custom CSS Class](#custom-css-class)
22
+ - [Custom CSS Class and ID](#custom-css-class-and-id)
23
+ - [Using Unordered/Ordered lists](#using-unorderedordered-lists)
24
+ - [Alternative Tools](#alternative-tools)
22
25
 
23
26
  ## Installation
24
27
 
@@ -50,7 +53,7 @@ toc: true
50
53
  There are three Liquid filters, which can be applied to HTML content,
51
54
  e.g. the Liquid variable `content` available in Jekyll's templates.
52
55
 
53
- ### 1. Basic Usage
56
+ ### Basic Usage
54
57
 
55
58
  #### `toc` filter
56
59
 
@@ -62,11 +65,11 @@ Add the `toc` filter to your site's `{{ content }}` (e.g. `_layouts/post.html`).
62
65
 
63
66
  This filter places the TOC directly above the content.
64
67
 
65
- ### 2. Advanced Usage
68
+ ### Advanced Usage
66
69
 
67
70
  If you'd like separated TOC and content, you can use `{% toc %}` tag (or `toc_only` filter) and `inject_anchors` filter.
68
71
 
69
- #### `{% toc %}` tag
72
+ #### `{% toc %}` tag / `toc_only` filter
70
73
 
71
74
  Generates the TOC itself as described [below](#generated-html).
72
75
  Mostly useful in cases where the TOC should _not_ be placed immediately
@@ -85,7 +88,8 @@ above the content but at some other place of the page, i.e. an aside.
85
88
 
86
89
  :warning: **`{% toc %}` Tag Limitation**
87
90
 
88
- `{% toc %}` can be available only in [Jekyll Posts](https://jekyllrb.com/docs/step-by-step/08-blogging/) and [Jekyll Collections](https://jekyllrb.com/docs/collections/). If you'd like to use `{% toc %}` except posts or collections, please use `toc_only` filter as described below.
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.
89
93
 
90
94
  ```html
91
95
  <div>
@@ -114,10 +118,10 @@ location with the `toc_only` filter.
114
118
 
115
119
  ## Generated HTML
116
120
 
117
- 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.
118
122
 
119
123
  ```html
120
- <ul class="section-nav">
124
+ <ul id="toc" class="section-nav">
121
125
  <li class="toc-entry toc-h1"><a href="#heading1">Heading.1</a>
122
126
  <ul>
123
127
  <li class="toc-entry toc-h2"><a href="#heading1-1">Heading.1-1</a></li>
@@ -140,52 +144,69 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
140
144
 
141
145
  ![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
142
146
 
143
- ## Default Configuration
147
+ ## Customization
148
+
149
+ jekyll-toc is customizable on `_config.yml`.
150
+
151
+ ### Default Configuration
144
152
 
145
153
  ```yml
154
+ # _config.yml
146
155
  toc:
147
156
  min_level: 1
148
157
  max_level: 6
158
+ ordered_list: false
149
159
  no_toc_section_class: no_toc_section
160
+ list_id: toc
150
161
  list_class: section-nav
151
162
  sublist_class: ''
152
163
  item_class: toc-entry
153
164
  item_prefix: toc-
154
165
  ```
155
166
 
156
- ## Customization
157
-
158
167
  ### TOC levels
159
168
 
160
- The toc levels can be configured on `_config.yml`:
161
-
162
169
  ```yml
170
+ # _config.yml
163
171
  toc:
164
172
  min_level: 2 # default: 1
165
173
  max_level: 5 # default: 6
166
174
  ```
167
175
 
168
- The default level range is `<h1>` to `<h6>`.
176
+ The default heading range is from `<h1>` to `<h6>`.
177
+
178
+ ### Enable TOC by default
179
+
180
+ You can enable TOC by default with [Front Matter Defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/):
181
+
182
+ ```yml
183
+ # _config.yml
184
+ defaults:
185
+ - scope:
186
+ path: ""
187
+ values:
188
+ toc: true
189
+ ```
169
190
 
170
191
  ### Skip TOC
171
192
 
172
- The heading is ignored in the toc when you add `no_toc` to the class.
193
+ The heading is ignored in the toc by adding `no_toc` class.
173
194
 
174
195
  ```html
175
196
  <h1>h1</h1>
176
- <h1 class="no_toc">This heading is ignored in the toc</h1>
197
+ <h1 class="no_toc">This heading is ignored in the TOC</h1>
177
198
  <h2>h2</h2>
178
199
  ```
179
200
 
180
- ### Skip TOC Section
201
+ ### Skip TOC Sectionally
181
202
 
182
203
  The headings are ignored inside the element which has `no_toc_section` class.
183
204
 
184
205
  ```html
185
206
  <h1>h1</h1>
186
207
  <div class="no_toc_section">
187
- <h2>This heading is ignored in the toc</h2>
188
- <h3>This heading is ignored in the toc</h3>
208
+ <h2>This heading is ignored in the TOC</h2>
209
+ <h3>This heading is ignored in the TOC</h3>
189
210
  </div>
190
211
  <h4>h4</h4>
191
212
  ```
@@ -195,13 +216,15 @@ Which would result in only the `<h1>` & `<h4>` within the example being included
195
216
  The class can be configured on `_config.yml`:
196
217
 
197
218
  ```yml
219
+ # _config.yml
198
220
  toc:
199
221
  no_toc_section_class: exclude # default: no_toc_section
200
222
  ```
201
223
 
202
- Configuring multiple classes for `no_toc_section_class` is allowed:
224
+ Configuring multiple classes are allowed:
203
225
 
204
226
  ```yml
227
+ # _config.yml
205
228
  toc:
206
229
  no_toc_section_class:
207
230
  - no_toc_section
@@ -227,21 +250,64 @@ The toc can be modified with CSS. The sample CSS is the following.
227
250
 
228
251
  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`.
229
252
 
230
- 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. For example, the TOC entry linking to a heading `<h1>...</h1>` (a single
231
- `#` in Markdown) will get the CSS class `toc-h1`.
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.
254
+ For example, the TOC entry linking to a heading `<h1>...</h1>` (a single `#` in Markdown) will get the CSS class `toc-h1`.
232
255
 
233
- ### Custom CSS Class
256
+ ### Custom CSS Class and ID
234
257
 
235
258
  You can apply custom CSS classes to the generated `<ul>` and `<li>` tags.
236
259
 
237
260
  ```yml
261
+ # _config.yml
262
+ toc:
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-":
268
+ ```
269
+
270
+ ### Using Unordered/Ordered lists
271
+
272
+ By default the table of contents will be generated as an unordered list via `<ul></ul>` tags. This can be configured to use ordered lists instead `<ol></ol>`.
273
+ This can be configured in `_config.yml`:
274
+
275
+ ```yml
276
+ # _config.yml
238
277
  toc:
239
- # Default is "section-nav":
278
+ ordered_list: true # default is false
279
+ ```
280
+
281
+ In order to change the list type, use the [list-style-type](https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type) css property.
282
+ Add a class to the `sublist_class` configuration to append it to the `ol` tags so that you can add the `list-style-type` property.
283
+
284
+ Example
285
+
286
+ ```yml
287
+ # _config.yml
288
+ toc:
289
+ ordered_list: true
240
290
  list_class: my-list-class
241
- # Default is no class for sublists:
242
291
  sublist_class: my-sublist-class
243
- # Default is "toc-entry":
244
- item_class: my-item-class
245
- # Default is "toc-":
246
- item_prefix: item-
247
292
  ```
293
+
294
+ ```css
295
+ .my-list-class {
296
+ list-style-type: upper-alpha;
297
+ }
298
+
299
+ .my-sublist-class: {
300
+ list-style-type: lower-alpha;
301
+ }
302
+ ```
303
+
304
+ This will produce:
305
+
306
+ ![screenshot](https://user-images.githubusercontent.com/7675276/85813980-a0ea5a80-b719-11ea-9458-ccf9b86a778b.png)
307
+
308
+ ## Alternative Tools
309
+
310
+ - Adding anchor to headings
311
+ - [AnchorJS](https://www.bryanbraun.com/anchorjs/)
312
+ - Generating TOC for kramdown content
313
+ - [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))
@@ -7,7 +7,10 @@ gem "minitest-reporters"
7
7
  gem "minitest"
8
8
  gem "pry"
9
9
  gem "rake"
10
- gem "rubocop", "~> 0.81"
10
+ gem "rubocop-minitest"
11
+ gem "rubocop-performance"
12
+ gem "rubocop-rake"
13
+ gem "rubocop"
11
14
  gem "simplecov", "~> 0.17.1"
12
15
  gem "jekyll", "3.8"
13
16
 
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "minitest-reporters"
7
+ gem "minitest"
8
+ gem "pry"
9
+ gem "rake"
10
+ gem "rubocop-minitest"
11
+ gem "rubocop-performance"
12
+ gem "rubocop-rake"
13
+ gem "rubocop"
14
+ gem "simplecov", "~> 0.17.1"
15
+ gem "jekyll", "3.9"
16
+
17
+ gemspec path: "../"
@@ -7,7 +7,10 @@ gem "minitest-reporters"
7
7
  gem "minitest"
8
8
  gem "pry"
9
9
  gem "rake"
10
- gem "rubocop", "~> 0.81"
10
+ gem "rubocop-minitest"
11
+ gem "rubocop-performance"
12
+ gem "rubocop-rake"
13
+ gem "rubocop"
11
14
  gem "simplecov", "~> 0.17.1"
12
15
  gem "jekyll", "4.0"
13
16
 
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "minitest-reporters"
7
+ gem "minitest"
8
+ gem "pry"
9
+ gem "rake"
10
+ gem "rubocop-minitest"
11
+ gem "rubocop-performance"
12
+ gem "rubocop-rake"
13
+ gem "rubocop"
14
+ gem "simplecov", "~> 0.17.1"
15
+ gem "jekyll", "4.1"
16
+
17
+ gemspec path: "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "minitest-reporters"
7
+ gem "minitest"
8
+ gem "pry"
9
+ gem "rake"
10
+ gem "rubocop-minitest"
11
+ gem "rubocop-performance"
12
+ gem "rubocop-rake"
13
+ gem "rubocop"
14
+ gem "simplecov", "~> 0.17.1"
15
+ gem "jekyll", "4.2"
16
+
17
+ gemspec path: "../"
@@ -8,17 +8,17 @@ 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 table of contents.'
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|features)/})
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'
21
21
 
22
- spec.add_dependency 'jekyll', '>= 3.8'
22
+ spec.add_dependency 'jekyll', '>= 3.9'
23
23
  spec.add_dependency 'nokogiri', '~> 1.10'
24
24
  end
@@ -4,13 +4,15 @@ module Jekyll
4
4
  module TableOfContents
5
5
  # jekyll-toc configuration class
6
6
  class Configuration
7
- attr_reader :toc_levels, :no_toc_class, :no_toc_section_class,
8
- :list_class, :sublist_class, :item_class, :item_prefix
7
+ attr_reader :toc_levels, :no_toc_class, :ordered_list, :no_toc_section_class,
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
+ 'ordered_list' => false,
13
14
  'no_toc_section_class' => 'no_toc_section',
15
+ 'list_id' => 'toc',
14
16
  'list_class' => 'section-nav',
15
17
  'sublist_class' => '',
16
18
  'item_class' => 'toc-entry',
@@ -21,8 +23,10 @@ module Jekyll
21
23
  options = generate_option_hash(options)
22
24
 
23
25
  @toc_levels = options['min_level']..options['max_level']
26
+ @ordered_list = options['ordered_list']
24
27
  @no_toc_class = 'no_toc'
25
28
  @no_toc_section_class = options['no_toc_section_class']
29
+ @list_id = options['list_id']
26
30
  @list_class = options['list_class']
27
31
  @sublist_class = options['sublist_class']
28
32
  @item_class = options['item_class']
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def build_toc
22
- %(<ul class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}</ul>)
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
@@ -74,7 +74,7 @@ module Jekyll
74
74
  next_i = i + 1
75
75
  if next_i < entries.count && entries[next_i][:h_num] > min_h_num
76
76
  nest_entries = get_nest_entries(entries[next_i, entries.count], min_h_num)
77
- toc_list << %(\n<ul#{ul_attributes}>\n#{build_toc_list(nest_entries)}</ul>\n)
77
+ toc_list << %(\n<#{list_tag}#{ul_attributes}>\n#{build_toc_list(nest_entries)}</#{list_tag}>\n)
78
78
  i += nest_entries.count
79
79
  end
80
80
  # Add the closing tag for the current entry in the list
@@ -107,7 +107,7 @@ module Jekyll
107
107
  end
108
108
 
109
109
  def toc_headings_in_no_toc_section
110
- if @configuration.no_toc_section_class.is_a? Array
110
+ if @configuration.no_toc_section_class.is_a?(Array)
111
111
  @configuration.no_toc_section_class.map { |cls| toc_headings_within(cls) }.join(',')
112
112
  else
113
113
  toc_headings_within(@configuration.no_toc_section_class)
@@ -121,6 +121,10 @@ module Jekyll
121
121
  def ul_attributes
122
122
  @ul_attributes ||= @configuration.sublist_class.empty? ? '' : %( class="#{@configuration.sublist_class}")
123
123
  end
124
+
125
+ def list_tag
126
+ @list_tag ||= @configuration.ordered_list ? 'ol' : 'ul'
127
+ end
124
128
  end
125
129
  end
126
130
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module TableOfContents
5
- VERSION = '0.14.0'
5
+ VERSION = '0.17.0'
6
6
  end
7
7
  end
@@ -18,6 +18,6 @@ class TestInjectAnchorsFilter < Minitest::Test
18
18
  def test_does_not_inject_toc
19
19
  html = @parser.inject_anchors_into_html
20
20
 
21
- assert_nil(/<ul class="section-nav">/ =~ html)
21
+ refute_includes(html, %(<ul id="toc" class="section-nav">))
22
22
  end
23
23
  end
@@ -5,7 +5,7 @@ require 'test_helper'
5
5
  class TestInvalidOptions < Minitest::Test
6
6
  BASE_HTML = '<h1>h1</h1>'
7
7
  EXPECTED_HTML = <<~HTML.chomp
8
- <ul class="section-nav">
8
+ <ul id="toc" class="section-nav">
9
9
  <li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
10
10
  </ul>
11
11
  HTML
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class TestOrderedList < Minitest::Test
6
+ include TestHelpers
7
+
8
+ def test_default_configuration
9
+ configuration = Jekyll::TableOfContents::Configuration.new({})
10
+
11
+ refute(configuration.ordered_list)
12
+ end
13
+
14
+ def test_disabled_ordered_list
15
+ configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => false)
16
+
17
+ refute(configuration.ordered_list)
18
+ end
19
+
20
+ def test_enabled_ordered_list
21
+ configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => true)
22
+
23
+ assert(configuration.ordered_list)
24
+ end
25
+
26
+ def test_basic_ordered_list_top_heading
27
+ parse_with_ordered_list
28
+ html = @parser.toc
29
+
30
+ assert_match(/^<ol id="toc" class="section-nav">/, html)
31
+ end
32
+
33
+ def test_ordered_list_sub_headings
34
+ parse_with_ordered_list
35
+ html = @parser.toc
36
+
37
+ assert_match(/<ol>\n<li class="toc-entry/, html)
38
+ end
39
+
40
+ def test_ordered_list_top_heading_with_classes
41
+ parse_with_ordered_list_and_classes
42
+ html = @parser.toc
43
+
44
+ assert_match(/^<ol id="toc" class="top-list-class">/, html)
45
+ end
46
+
47
+ def test_ordered_list_sub_headings_with_classes
48
+ parse_with_ordered_list_and_classes
49
+ html = @parser.toc
50
+
51
+ assert_match(/<ol class="sublist-class">/, html)
52
+ end
53
+
54
+ def test_ordered_list_subheadings_with_classes_nested_structure
55
+ parse_with_ordered_list_and_classes
56
+ html = @parser.toc
57
+
58
+ occurrences = html.scan(/<ol class="sublist-class">/).count
59
+
60
+ assert_equal(5, occurrences)
61
+ end
62
+
63
+ private
64
+
65
+ def parse_with_ordered_list
66
+ read_html_and_create_parser('ordered_list' => true)
67
+ end
68
+
69
+ def parse_with_ordered_list_and_classes
70
+ read_html_and_create_parser(
71
+ 'ordered_list' => true,
72
+ 'list_class' => 'top-list-class',
73
+ 'sublist_class' => 'sublist-class'
74
+ )
75
+ end
76
+ end
@@ -31,6 +31,6 @@ class TestTOCFilter < Minitest::Test
31
31
  def test_injects_toc_container
32
32
  html = @parser.toc
33
33
 
34
- assert_match(/<ul class="section-nav">/, html)
34
+ assert_match(/<ul id="toc" class="section-nav">/, html)
35
35
  end
36
36
  end
@@ -12,12 +12,12 @@ class TestTOCOnlyFilter < Minitest::Test
12
12
  def test_injects_toc_container
13
13
  html = @parser.build_toc
14
14
 
15
- assert_match(/<ul class="section-nav">/, html)
15
+ assert_includes(html, %(<ul id="toc" 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
- assert_nil(%r{<h1>Simple H1</h1>} =~ html)
21
+ refute_includes(html, %(<h1>Simple H1</h1>))
22
22
  end
23
23
  end
@@ -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>&amp; &lt; &gt;</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">&lt;base href&gt;</a></li>
190
190
  <li class="toc-entry toc-h1"><a href="#--">&amp; &lt; &gt;</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>
@@ -3,25 +3,29 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class TestConfiguration < Minitest::Test
6
- def test_default_conf1guration
6
+ def test_default_configuration
7
7
  configuration = Jekyll::TableOfContents::Configuration.new({})
8
8
 
9
- assert_equal configuration.toc_levels, 1..6
10
- assert_equal configuration.no_toc_section_class, 'no_toc_section'
11
- assert_equal configuration.list_class, 'section-nav'
12
- assert_equal configuration.sublist_class, ''
13
- assert_equal configuration.item_class, 'toc-entry'
14
- assert_equal configuration.item_prefix, 'toc-'
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('toc', configuration.list_id)
13
+ assert_equal('section-nav', configuration.list_class)
14
+ assert_equal('', configuration.sublist_class)
15
+ assert_equal('toc-entry', configuration.item_class)
16
+ assert_equal('toc-', configuration.item_prefix)
15
17
  end
16
18
 
17
19
  def test_type_error
18
20
  configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
19
21
 
20
- assert_equal configuration.toc_levels, 1..6
21
- assert_equal configuration.no_toc_section_class, 'no_toc_section'
22
- assert_equal configuration.list_class, 'section-nav'
23
- assert_equal configuration.sublist_class, ''
24
- assert_equal configuration.item_class, 'toc-entry'
25
- assert_equal configuration.item_prefix, 'toc-'
22
+ assert_equal(1..6, configuration.toc_levels)
23
+ refute(configuration.ordered_list)
24
+ assert_equal('no_toc_section', configuration.no_toc_section_class)
25
+ assert_equal('toc', configuration.list_id)
26
+ assert_equal('section-nav', configuration.list_class)
27
+ assert_equal('', configuration.sublist_class)
28
+ assert_equal('toc-entry', configuration.item_class)
29
+ assert_equal('toc-', configuration.item_prefix)
26
30
  end
27
31
  end
@@ -20,7 +20,7 @@ SIMPLE_HTML = <<~HTML
20
20
  HTML
21
21
 
22
22
  module TestHelpers
23
- def read_html_and_create_parser
24
- @parser = Jekyll::TableOfContents::Parser.new(SIMPLE_HTML)
23
+ def read_html_and_create_parser(options = {})
24
+ @parser = Jekyll::TableOfContents::Parser.new(SIMPLE_HTML, options)
25
25
  end
26
26
  end
@@ -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 "<ul class=\"section-nav\">\n</ul>", toc_only(DUMMY_HTML)
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 "<ul class=\"section-nav\">\n</ul>#{DUMMY_HTML}", toc(DUMMY_HTML)
37
+ assert_equal %(<ul id="toc" class="section-nav">\n</ul>#{DUMMY_HTML}), toc(DUMMY_HTML)
38
38
  end
39
39
 
40
40
  private
@@ -36,7 +36,7 @@ class TestKramdownList < Minitest::Test
36
36
  assert_equal(expected, actual)
37
37
  end
38
38
 
39
- def test_kramdown_list_1
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 test_kramdown_list_2
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 test_kramdown_list_3
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 test_kramdown_list_4
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 test_kramdown_list_5
146
+ def test_kramdown_list_l1_l3_l1
147
147
  text = <<~MARKDOWN
148
148
  * level-1
149
149
  * level-3
@@ -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 tag.render(context), "<ul class=\"section-nav\">\n<li class=\"toc-entry toc-h1\"><a href=\"#test\">test</a></li>\n</ul>"
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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-toc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - toshimaru
8
8
  - torbjoernk
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-05 00:00:00.000000000 Z
12
+ date: 2021-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3.8'
20
+ version: '3.9'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '3.8'
27
+ version: '3.9'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: nokogiri
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -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 table
43
- of contents.
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"
@@ -58,7 +59,10 @@ files:
58
59
  - README.md
59
60
  - Rakefile
60
61
  - gemfiles/jekyll_3.8.gemfile
62
+ - gemfiles/jekyll_3.9.gemfile
61
63
  - gemfiles/jekyll_4.0.gemfile
64
+ - gemfiles/jekyll_4.1.gemfile
65
+ - gemfiles/jekyll_4.2.gemfile
62
66
  - jekyll-toc.gemspec
63
67
  - lib/jekyll-toc.rb
64
68
  - lib/table_of_contents/configuration.rb
@@ -67,6 +71,7 @@ files:
67
71
  - lib/table_of_contents/version.rb
68
72
  - test/parser/test_inject_anchors_filter.rb
69
73
  - test/parser/test_invalid_options.rb
74
+ - test/parser/test_ordered_list.rb
70
75
  - test/parser/test_toc_filter.rb
71
76
  - test/parser/test_toc_only_filter.rb
72
77
  - test/parser/test_various_toc_html.rb
@@ -79,7 +84,7 @@ homepage: https://github.com/toshimaru/jekyll-toc
79
84
  licenses:
80
85
  - MIT
81
86
  metadata: {}
82
- post_install_message:
87
+ post_install_message:
83
88
  rdoc_options: []
84
89
  require_paths:
85
90
  - lib
@@ -94,13 +99,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
99
  - !ruby/object:Gem::Version
95
100
  version: '0'
96
101
  requirements: []
97
- rubygems_version: 3.1.2
98
- signing_key:
102
+ rubygems_version: 3.1.4
103
+ signing_key:
99
104
  specification_version: 4
100
105
  summary: Jekyll Table of Contents plugin
101
106
  test_files:
102
107
  - test/parser/test_inject_anchors_filter.rb
103
108
  - test/parser/test_invalid_options.rb
109
+ - test/parser/test_ordered_list.rb
104
110
  - test/parser/test_toc_filter.rb
105
111
  - test/parser/test_toc_only_filter.rb
106
112
  - test/parser/test_various_toc_html.rb