jekyll-toc 0.12.1 → 0.15.0.rc
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/ci.yml +32 -0
- data/.github/workflows/coverage.yml +22 -0
- data/.github/workflows/rubocop.yml +19 -0
- data/.rubocop.yml +26 -9
- data/Appraisals +5 -9
- data/Gemfile +8 -0
- data/LICENSE.md +1 -1
- data/README.md +55 -8
- data/gemfiles/jekyll_3.8.gemfile +7 -0
- data/gemfiles/jekyll_3.9.gemfile +14 -0
- data/gemfiles/jekyll_4.0.gemfile +14 -0
- data/gemfiles/jekyll_4.1.gemfile +14 -0
- data/jekyll-toc.gemspec +8 -14
- data/lib/jekyll-toc.rb +0 -2
- data/lib/table_of_contents/configuration.rb +4 -2
- data/lib/table_of_contents/helper.rb +17 -0
- data/lib/table_of_contents/parser.rb +12 -8
- data/lib/table_of_contents/version.rb +7 -0
- data/test/parser/{test_option_error.rb → test_invalid_options.rb} +6 -14
- data/test/parser/test_ordered_list.rb +76 -0
- data/test/parser/test_various_toc_html.rb +147 -215
- data/test/test_configuration.rb +3 -1
- data/test/test_helper.rb +3 -3
- data/test/test_toc_tag.rb +1 -1
- metadata +30 -121
- data/.travis.yml +0 -23
- data/gemfiles/jekyll_3.6.gemfile +0 -7
- data/gemfiles/jekyll_3.7.gemfile +0 -7
- data/lib/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d791df4c69353cee2810d445dc565746e9d4ed2f7f738e205f6ee2fef19d369
|
4
|
+
data.tar.gz: '084bc15ad6fe3fb08b2ad83e979e08d93ffb988adbccc6c7981479cd210d9de4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44021a6c5bf17fa105b698571d43715aa381297b47355f4f439179063f695318f8071a8c1120318682c9eb25c17d7067fcacfdfc0ea5ce62995428f3e2f3649f
|
7
|
+
data.tar.gz: 69af07e31563443aa18492717b820aa3d274cc2e1cbb520a9b1489b87c72492ef3611fb96a25403565ea9e809161cffb2809aaead154b047984dac67da268bcb
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
ruby: [2.4, 2.5, 2.6, 2.7]
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/jekyll_3.8.gemfile
|
10
|
+
- gemfiles/jekyll_3.9.gemfile
|
11
|
+
- gemfiles/jekyll_4.0.gemfile
|
12
|
+
- gemfiles/jekyll_4.1.gemfile
|
13
|
+
exclude:
|
14
|
+
- ruby: 2.4
|
15
|
+
gemfile: gemfiles/jekyll_4.0.gemfile
|
16
|
+
- ruby: 2.4
|
17
|
+
gemfile: gemfiles/jekyll_4.1.gemfile
|
18
|
+
env:
|
19
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
24
|
+
uses: eregon/use-ruby-action@master
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
27
|
+
- name: bundle install
|
28
|
+
run: |
|
29
|
+
gem install bundler
|
30
|
+
bundle install --jobs 4 --retry 3
|
31
|
+
- name: Run Test
|
32
|
+
run: bundle exec rake
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Coverage
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
ruby: [2.6]
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
name: coverage
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
13
|
+
uses: eregon/use-ruby-action@master
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
- name: bundle install
|
17
|
+
run: bundle install --jobs 4 --retry 3
|
18
|
+
- uses: paambaati/codeclimate-action@v2.4.0
|
19
|
+
env:
|
20
|
+
CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
|
21
|
+
with:
|
22
|
+
coverageCommand: bundle exec rake
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
ruby: [2.6]
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
name: rubocop
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
13
|
+
uses: eregon/use-ruby-action@master
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
- name: bundle install
|
17
|
+
run: bundle install --jobs 4 --retry 3
|
18
|
+
- name: Run RuboCop
|
19
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -1,22 +1,39 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.4
|
3
3
|
Exclude:
|
4
|
-
-
|
5
|
-
-
|
4
|
+
- "*.gemspec"
|
5
|
+
- "gemfiles/*"
|
6
|
+
- "vendor/**/*"
|
6
7
|
- Rakefile
|
7
8
|
- Gemfile
|
8
9
|
|
9
|
-
Metrics/LineLength:
|
10
|
-
Enabled: false
|
11
|
-
|
12
10
|
Metrics/MethodLength:
|
13
11
|
Enabled: false
|
14
|
-
|
15
12
|
Metrics/AbcSize:
|
16
13
|
Enabled: false
|
17
|
-
|
18
14
|
Metrics/ClassLength:
|
19
15
|
Enabled: false
|
20
16
|
|
21
|
-
|
17
|
+
Naming/FileName:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Enabled: false
|
22
|
+
Layout/SpaceAroundMethodCallOperator:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Lint/RaiseException:
|
26
|
+
Enabled: true
|
27
|
+
Lint/StructNewOverride:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Style/WordArray:
|
22
31
|
Enabled: false
|
32
|
+
Style/HashEachMethods:
|
33
|
+
Enabled: true
|
34
|
+
Style/HashTransformKeys:
|
35
|
+
Enabled: true
|
36
|
+
Style/HashTransformValues:
|
37
|
+
Enabled: true
|
38
|
+
Style/ExponentialNotation:
|
39
|
+
Enabled: true
|
data/Appraisals
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
gem 'jekyll', '3.8'
|
5
|
-
end
|
6
|
-
|
7
|
-
appraise 'jekyll-3.7' do
|
8
|
-
gem 'jekyll', '3.7'
|
9
|
-
end
|
3
|
+
SUPPORTED_VERSIONS = %w[3.8 3.9 4.0 4.1].freeze
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
SUPPORTED_VERSIONS.each do |version|
|
6
|
+
appraise "jekyll-#{version}" do
|
7
|
+
gem 'jekyll', version
|
8
|
+
end
|
13
9
|
end
|
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# jekyll-toc
|
2
2
|
|
3
|
-
|
4
|
-
[](
|
3
|
+

|
4
|
+
[](https://badge.fury.io/rb/jekyll-toc)
|
5
5
|
[](https://codeclimate.com/github/toshimaru/jekyll-toc)
|
6
6
|
[](https://codeclimate.com/github/toshimaru/jekyll-toc/test_coverage)
|
7
7
|
|
@@ -19,6 +19,7 @@
|
|
19
19
|
- [Skip TOC Section](#skip-toc-section)
|
20
20
|
- [CSS Styling](#css-styling)
|
21
21
|
- [Custom CSS Class](#custom-css-class)
|
22
|
+
- [Using Unordered/Ordered lists](#using-unorderedordered-lists)
|
22
23
|
|
23
24
|
## Installation
|
24
25
|
|
@@ -64,11 +65,9 @@ This filter places the TOC directly above the content.
|
|
64
65
|
|
65
66
|
### 2. Advanced Usage
|
66
67
|
|
67
|
-
If you'd like separated TOC and content, you can use `toc_only` and `inject_anchors`
|
68
|
+
If you'd like separated TOC and content, you can use `{% toc %}` tag (or `toc_only` filter) and `inject_anchors` filter.
|
68
69
|
|
69
|
-
####
|
70
|
-
|
71
|
-
⚠️ Please use `{% toc %}` instead of `{{ content | toc_only }}`.
|
70
|
+
#### `{% toc %}` tag
|
72
71
|
|
73
72
|
Generates the TOC itself as described [below](#generated-html).
|
74
73
|
Mostly useful in cases where the TOC should _not_ be placed immediately
|
@@ -85,9 +84,20 @@ above the content but at some other place of the page, i.e. an aside.
|
|
85
84
|
</div>
|
86
85
|
```
|
87
86
|
|
88
|
-
|
87
|
+
:warning: **`{% toc %}` Tag Limitation**
|
88
|
+
|
89
|
+
`{% 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.
|
89
90
|
|
90
|
-
|
91
|
+
```html
|
92
|
+
<div>
|
93
|
+
<div id="table-of-contents">
|
94
|
+
{{ content | toc_only }}
|
95
|
+
</div>
|
96
|
+
<div id="markdown-content">
|
97
|
+
{{ content | inject_anchors }}
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
```
|
91
101
|
|
92
102
|
#### `inject_anchors` filter
|
93
103
|
|
@@ -137,6 +147,7 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
|
|
137
147
|
toc:
|
138
148
|
min_level: 1
|
139
149
|
max_level: 6
|
150
|
+
ordered_list: false
|
140
151
|
no_toc_section_class: no_toc_section
|
141
152
|
list_class: section-nav
|
142
153
|
sublist_class: ''
|
@@ -236,3 +247,39 @@ toc:
|
|
236
247
|
# Default is "toc-":
|
237
248
|
item_prefix: item-
|
238
249
|
```
|
250
|
+
|
251
|
+
### Using Unordered/Ordered lists
|
252
|
+
|
253
|
+
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>`.
|
254
|
+
This can be configured in `_config.yml`:
|
255
|
+
|
256
|
+
```yml
|
257
|
+
toc:
|
258
|
+
ordered_list: true # default is false
|
259
|
+
```
|
260
|
+
|
261
|
+
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.
|
262
|
+
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.
|
263
|
+
|
264
|
+
Example
|
265
|
+
|
266
|
+
```yml
|
267
|
+
toc:
|
268
|
+
ordered_list: true
|
269
|
+
list_class: my-list-class
|
270
|
+
sublist_class: my-sublist-class
|
271
|
+
```
|
272
|
+
|
273
|
+
```css
|
274
|
+
.my-list-class {
|
275
|
+
list-style-type: upper-alpha;
|
276
|
+
}
|
277
|
+
|
278
|
+
.my-sublist-class: {
|
279
|
+
list-style-type: lower-alpha;
|
280
|
+
}
|
281
|
+
```
|
282
|
+
|
283
|
+
This will produce:
|
284
|
+
|
285
|
+

|
data/gemfiles/jekyll_3.8.gemfile
CHANGED
@@ -0,0 +1,14 @@
|
|
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", "~> 0.81"
|
11
|
+
gem "simplecov", "~> 0.17.1"
|
12
|
+
gem "jekyll", "3.9"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
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", "~> 0.81"
|
11
|
+
gem "simplecov", "~> 0.17.1"
|
12
|
+
gem "jekyll", "4.0"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
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", "~> 0.81"
|
11
|
+
gem "simplecov", "~> 0.17.1"
|
12
|
+
gem "jekyll", "4.1"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
data/jekyll-toc.gemspec
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('../lib', __FILE__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'version'
|
5
|
+
require 'table_of_contents/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
8
|
spec.name = 'jekyll-toc'
|
7
|
-
spec.version =
|
9
|
+
spec.version = Jekyll::TableOfContents::VERSION
|
8
10
|
spec.summary = 'Jekyll Table of Contents plugin'
|
9
|
-
spec.description = '
|
11
|
+
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a table of contents.'
|
10
12
|
spec.authors = %w(toshimaru torbjoernk)
|
11
13
|
spec.email = 'me@toshimaru.net'
|
12
14
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -15,16 +17,8 @@ Gem::Specification.new do |spec|
|
|
15
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
18
|
spec.require_paths = ['lib']
|
17
19
|
|
18
|
-
spec.required_ruby_version = '>= 2.
|
19
|
-
|
20
|
-
spec.add_runtime_dependency 'nokogiri', '~> 1.9'
|
20
|
+
spec.required_ruby_version = '>= 2.4'
|
21
21
|
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency 'minitest', '~> 5.11'
|
25
|
-
spec.add_development_dependency 'minitest-reporters'
|
26
|
-
spec.add_development_dependency 'pry'
|
27
|
-
spec.add_development_dependency 'rake'
|
28
|
-
spec.add_development_dependency 'rubocop'
|
29
|
-
spec.add_development_dependency 'simplecov'
|
22
|
+
spec.add_dependency 'jekyll', '>= 3.8'
|
23
|
+
spec.add_dependency 'nokogiri', '~> 1.10'
|
30
24
|
end
|
data/lib/jekyll-toc.rb
CHANGED
@@ -20,8 +20,6 @@ module Jekyll
|
|
20
20
|
module TableOfContentsFilter
|
21
21
|
# Deprecated method. Removed in v1.0.
|
22
22
|
def toc_only(html)
|
23
|
-
Jekyll.logger.warn 'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.',
|
24
|
-
'Use `{% toc %}` instead of `{{ content | toc_only }}`.'
|
25
23
|
return '' unless toc_enabled?
|
26
24
|
|
27
25
|
TableOfContents::Parser.new(html, toc_config).build_toc
|
@@ -4,12 +4,13 @@ module Jekyll
|
|
4
4
|
module TableOfContents
|
5
5
|
# jekyll-toc configuration class
|
6
6
|
class Configuration
|
7
|
-
|
8
|
-
|
7
|
+
attr_reader :toc_levels, :no_toc_class, :ordered_list, :no_toc_section_class,
|
8
|
+
: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',
|
14
15
|
'list_class' => 'section-nav',
|
15
16
|
'sublist_class' => '',
|
@@ -21,6 +22,7 @@ module Jekyll
|
|
21
22
|
options = generate_option_hash(options)
|
22
23
|
|
23
24
|
@toc_levels = options['min_level']..options['max_level']
|
25
|
+
@ordered_list = options['ordered_list']
|
24
26
|
@no_toc_class = 'no_toc'
|
25
27
|
@no_toc_section_class = options['no_toc_section_class']
|
26
28
|
@list_class = options['list_class']
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module TableOfContents
|
5
|
+
# helper methods for Parser
|
6
|
+
module Helper
|
7
|
+
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
|
8
|
+
|
9
|
+
def generate_toc_id(text)
|
10
|
+
text = text.downcase
|
11
|
+
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation
|
12
|
+
.tr(' ', '-') # replace spaces with dash
|
13
|
+
CGI.escape(text)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'table_of_contents/helper'
|
4
|
+
|
3
5
|
module Jekyll
|
4
6
|
module TableOfContents
|
5
7
|
# Parse html contents and generate table of contents
|
6
8
|
class Parser
|
7
|
-
|
9
|
+
include ::Jekyll::TableOfContents::Helper
|
8
10
|
|
9
11
|
def initialize(html, options = {})
|
10
12
|
@doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
@@ -17,11 +19,12 @@ module Jekyll
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def build_toc
|
20
|
-
%(
|
22
|
+
%(<#{list_tag} class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}</#{list_tag}>)
|
21
23
|
end
|
22
24
|
|
23
25
|
def inject_anchors_into_html
|
24
26
|
@entries.each do |entry|
|
27
|
+
# NOTE: `entry[:id]` is automatically URL encoded by Nokogiri
|
25
28
|
entry[:header_content].add_previous_sibling(
|
26
29
|
%(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>)
|
27
30
|
)
|
@@ -41,10 +44,7 @@ module Jekyll
|
|
41
44
|
.reject { |n| n.classes.include?(@configuration.no_toc_class) }
|
42
45
|
.inject([]) do |entries, node|
|
43
46
|
text = node.text
|
44
|
-
id = node.attribute('id') || text
|
45
|
-
.downcase
|
46
|
-
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation
|
47
|
-
.tr(' ', '-') # replace spaces with dash
|
47
|
+
id = node.attribute('id') || generate_toc_id(text)
|
48
48
|
|
49
49
|
suffix_num = headers[id]
|
50
50
|
headers[id] += 1
|
@@ -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
|
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?
|
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
|