jekyll-toc 0.14.0 → 0.15.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +7 -3
- data/.github/workflows/coverage.yml +1 -1
- data/.github/workflows/rubocop.yml +1 -1
- data/Appraisals +5 -5
- data/README.md +39 -1
- data/gemfiles/jekyll_3.9.gemfile +14 -0
- data/gemfiles/jekyll_4.1.gemfile +14 -0
- data/lib/table_of_contents/configuration.rb +3 -1
- data/lib/table_of_contents/parser.rb +7 -3
- data/lib/table_of_contents/version.rb +1 -1
- data/test/parser/test_ordered_list.rb +76 -0
- data/test/test_configuration.rb +3 -1
- data/test/test_helper.rb +2 -2
- metadata +12 -8
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
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,16 +1,20 @@
|
|
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
7
|
ruby: [2.4, 2.5, 2.6, 2.7]
|
8
8
|
gemfile:
|
9
|
-
|
10
|
-
|
9
|
+
- gemfiles/jekyll_3.8.gemfile
|
10
|
+
- gemfiles/jekyll_3.9.gemfile
|
11
|
+
- gemfiles/jekyll_4.0.gemfile
|
12
|
+
- gemfiles/jekyll_4.1.gemfile
|
11
13
|
exclude:
|
12
14
|
- ruby: 2.4
|
13
15
|
gemfile: gemfiles/jekyll_4.0.gemfile
|
16
|
+
- ruby: 2.4
|
17
|
+
gemfile: gemfiles/jekyll_4.1.gemfile
|
14
18
|
env:
|
15
19
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
16
20
|
runs-on: ubuntu-latest
|
data/Appraisals
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
gem 'jekyll', '4.0'
|
5
|
-
end
|
3
|
+
SUPPORTED_VERSIONS = %w[3.8 3.9 4.0 4.1].freeze
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
SUPPORTED_VERSIONS.each do |version|
|
6
|
+
appraise "jekyll-#{version}" do
|
7
|
+
gem 'jekyll', version
|
8
|
+
end
|
9
9
|
end
|
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)](
|
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
|
|
@@ -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
|
|
@@ -146,6 +147,7 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
|
|
146
147
|
toc:
|
147
148
|
min_level: 1
|
148
149
|
max_level: 6
|
150
|
+
ordered_list: false
|
149
151
|
no_toc_section_class: no_toc_section
|
150
152
|
list_class: section-nav
|
151
153
|
sublist_class: ''
|
@@ -245,3 +247,39 @@ toc:
|
|
245
247
|
# Default is "toc-":
|
246
248
|
item_prefix: item-
|
247
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
|
+
![screenshot](https://user-images.githubusercontent.com/7675276/85813980-a0ea5a80-b719-11ea-9458-ccf9b86a778b.png)
|
@@ -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.1"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -4,12 +4,13 @@ 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,
|
7
|
+
attr_reader :toc_levels, :no_toc_class, :ordered_list, :no_toc_section_class,
|
8
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']
|
@@ -19,7 +19,7 @@ module Jekyll
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def build_toc
|
22
|
-
%(
|
22
|
+
%(<#{list_tag} 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
|
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
|
@@ -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
|
+
assert_equal configuration.ordered_list, false
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_disabled_ordered_list
|
15
|
+
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => false)
|
16
|
+
|
17
|
+
assert_equal configuration.ordered_list, false
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_enabled_ordered_list
|
21
|
+
configuration = Jekyll::TableOfContents::Configuration.new('ordered_list' => true)
|
22
|
+
|
23
|
+
assert_equal configuration.ordered_list, true
|
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 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 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 occurrences, 5
|
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
|
data/test/test_configuration.rb
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class TestConfiguration < Minitest::Test
|
6
|
-
def
|
6
|
+
def test_default_configuration
|
7
7
|
configuration = Jekyll::TableOfContents::Configuration.new({})
|
8
8
|
|
9
9
|
assert_equal configuration.toc_levels, 1..6
|
10
|
+
assert_equal configuration.ordered_list, false
|
10
11
|
assert_equal configuration.no_toc_section_class, 'no_toc_section'
|
11
12
|
assert_equal configuration.list_class, 'section-nav'
|
12
13
|
assert_equal configuration.sublist_class, ''
|
@@ -18,6 +19,7 @@ class TestConfiguration < Minitest::Test
|
|
18
19
|
configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
|
19
20
|
|
20
21
|
assert_equal configuration.toc_levels, 1..6
|
22
|
+
assert_equal configuration.ordered_list, false
|
21
23
|
assert_equal configuration.no_toc_section_class, 'no_toc_section'
|
22
24
|
assert_equal configuration.list_class, 'section-nav'
|
23
25
|
assert_equal configuration.sublist_class, ''
|
data/test/test_helper.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.15.0.rc
|
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-
|
12
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
@@ -58,7 +58,9 @@ files:
|
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
60
|
- gemfiles/jekyll_3.8.gemfile
|
61
|
+
- gemfiles/jekyll_3.9.gemfile
|
61
62
|
- gemfiles/jekyll_4.0.gemfile
|
63
|
+
- gemfiles/jekyll_4.1.gemfile
|
62
64
|
- jekyll-toc.gemspec
|
63
65
|
- lib/jekyll-toc.rb
|
64
66
|
- lib/table_of_contents/configuration.rb
|
@@ -67,6 +69,7 @@ files:
|
|
67
69
|
- lib/table_of_contents/version.rb
|
68
70
|
- test/parser/test_inject_anchors_filter.rb
|
69
71
|
- test/parser/test_invalid_options.rb
|
72
|
+
- test/parser/test_ordered_list.rb
|
70
73
|
- test/parser/test_toc_filter.rb
|
71
74
|
- test/parser/test_toc_only_filter.rb
|
72
75
|
- test/parser/test_various_toc_html.rb
|
@@ -79,7 +82,7 @@ homepage: https://github.com/toshimaru/jekyll-toc
|
|
79
82
|
licenses:
|
80
83
|
- MIT
|
81
84
|
metadata: {}
|
82
|
-
post_install_message:
|
85
|
+
post_install_message:
|
83
86
|
rdoc_options: []
|
84
87
|
require_paths:
|
85
88
|
- lib
|
@@ -90,17 +93,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
93
|
version: '2.4'
|
91
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
95
|
requirements:
|
93
|
-
- - "
|
96
|
+
- - ">"
|
94
97
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
98
|
+
version: 1.3.1
|
96
99
|
requirements: []
|
97
|
-
rubygems_version: 3.1.
|
98
|
-
signing_key:
|
100
|
+
rubygems_version: 3.1.4
|
101
|
+
signing_key:
|
99
102
|
specification_version: 4
|
100
103
|
summary: Jekyll Table of Contents plugin
|
101
104
|
test_files:
|
102
105
|
- test/parser/test_inject_anchors_filter.rb
|
103
106
|
- test/parser/test_invalid_options.rb
|
107
|
+
- test/parser/test_ordered_list.rb
|
104
108
|
- test/parser/test_toc_filter.rb
|
105
109
|
- test/parser/test_toc_only_filter.rb
|
106
110
|
- test/parser/test_various_toc_html.rb
|