@@ -112,17 +116,25 @@ They are of the form:
This is only useful when the TOC itself should be placed at some other
location with the `toc_only` filter.
-## Testing
+## Testing and Linting
To run the tests you `rake`. First install gem packages local and run `rake test`.
+Run tests
+
+```shell
+bundle exec rake test
+```
+
+Run liniting with rubocop
+
```shell
-rake test
+bundle exec rubocop
```
## Generated HTML
-jekyll-toc generates an unordered list. The HTML output is as follows.
+jekyll-toc generates an unordered list by default. The HTML output is as follows.
```html
@@ -148,53 +160,68 @@ jekyll-toc generates an unordered list. The HTML output is as follows.

-## Default Configuration
+## Customization
+
+jekyll-toc is customizable on `_config.yml`.
+
+### Default Configuration
```yml
+# _config.yml
toc:
min_level: 1
max_level: 6
+ ordered_list: false
no_toc_section_class: no_toc_section
list_class: section-nav
sublist_class: ''
item_class: toc-entry
item_prefix: toc-
- anchor_id_url_encoded: false
```
-## Customization
-
### TOC levels
-The toc levels can be configured on `_config.yml`:
-
```yml
+# _config.yml
toc:
min_level: 2 # default: 1
max_level: 5 # default: 6
```
-The default level range is `` to ``.
+The default heading range is from `` to ``.
+
+### Enable TOC by default
+
+You can enable TOC by default with [Front Matter Defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/):
+
+```yml
+# _config.yml
+defaults:
+ - scope:
+ path: ""
+ values:
+ toc: true
+```
### Skip TOC
-The heading is ignored in the toc when you add `no_toc` to the class.
+The heading is ignored in the toc by adding `no_toc` class.
```html
h1
-This heading is ignored in the toc
+This heading is ignored in the TOC
h2
```
-### Skip TOC Section
+### Skip TOC Sectionally
The headings are ignored inside the element which has `no_toc_section` class.
```html
h1
-
This heading is ignored in the toc
- This heading is ignored in the toc
+ This heading is ignored in the TOC
+ This heading is ignored in the TOC
h4
```
@@ -204,13 +231,15 @@ Which would result in only the `` & `` within the example being included
The class can be configured on `_config.yml`:
```yml
+# _config.yml
toc:
no_toc_section_class: exclude # default: no_toc_section
```
-Configuring multiple classes for `no_toc_section_class` is allowed:
+Configuring multiple classes are allowed:
```yml
+# _config.yml
toc:
no_toc_section_class:
- no_toc_section
@@ -236,14 +265,15 @@ The toc can be modified with CSS. The sample CSS is the following.
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`.
-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 `...
` (a single
-`#` in Markdown) will get the CSS class `toc-h1`.
+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 `...
` (a single `#` in Markdown) will get the CSS class `toc-h1`.
### Custom CSS Class
You can apply custom CSS classes to the generated `` and `- ` tags.
```yml
+# _config.yml
toc:
# Default is "section-nav":
list_class: my-list-class
@@ -254,3 +284,48 @@ toc:
# Default is "toc-":
item_prefix: item-
```
+
+### Using Unordered/Ordered lists
+
+By default the table of contents will be generated as an unordered list via `` tags. This can be configured to use ordered lists instead `
`.
+This can be configured in `_config.yml`:
+
+```yml
+# _config.yml
+toc:
+ ordered_list: true # default is false
+```
+
+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.
+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.
+
+Example
+
+```yml
+# _config.yml
+toc:
+ ordered_list: true
+ list_class: my-list-class
+ sublist_class: my-sublist-class
+```
+
+```css
+.my-list-class {
+ list-style-type: upper-alpha;
+}
+
+.my-sublist-class: {
+ list-style-type: lower-alpha;
+}
+```
+
+This will produce:
+
+
+
+## Alternative Tools
+
+- Adding anchor to headings
+ - [AnchorJS](https://www.bryanbraun.com/anchorjs/)
+- Generating TOC for kramdown content
+ - [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))
diff --git a/gemfiles/jekyll_3.8.gemfile b/gemfiles/jekyll_3.8.gemfile
new file mode 100644
index 0000000..d4ca717
--- /dev/null
+++ b/gemfiles/jekyll_3.8.gemfile
@@ -0,0 +1,14 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "appraisal"
+gem "minitest-reporters"
+gem "minitest"
+gem "pry"
+gem "rake"
+gem "rubocop", "~> 0.81"
+gem "simplecov", "~> 0.17.1"
+gem "jekyll", "3.8"
+
+gemspec path: "../"
diff --git a/gemfiles/jekyll_3.9.gemfile b/gemfiles/jekyll_3.9.gemfile
new file mode 100644
index 0000000..c5d50af
--- /dev/null
+++ b/gemfiles/jekyll_3.9.gemfile
@@ -0,0 +1,14 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "appraisal"
+gem "minitest-reporters"
+gem "minitest"
+gem "pry"
+gem "rake"
+gem "rubocop", "~> 0.81"
+gem "simplecov", "~> 0.17.1"
+gem "jekyll", "3.9"
+
+gemspec path: "../"
diff --git a/gemfiles/jekyll_4.0.gemfile b/gemfiles/jekyll_4.0.gemfile
index e6ba5d2..267a730 100644
--- a/gemfiles/jekyll_4.0.gemfile
+++ b/gemfiles/jekyll_4.0.gemfile
@@ -7,8 +7,8 @@ gem "minitest-reporters"
gem "minitest"
gem "pry"
gem "rake"
-gem "rubocop"
-gem "simplecov"
+gem "rubocop", "~> 0.81"
+gem "simplecov", "~> 0.17.1"
gem "jekyll", "4.0"
gemspec path: "../"
diff --git a/gemfiles/jekyll_4.1.gemfile b/gemfiles/jekyll_4.1.gemfile
new file mode 100644
index 0000000..d5296a3
--- /dev/null
+++ b/gemfiles/jekyll_4.1.gemfile
@@ -0,0 +1,14 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "appraisal"
+gem "minitest-reporters"
+gem "minitest"
+gem "pry"
+gem "rake"
+gem "rubocop", "~> 0.81"
+gem "simplecov", "~> 0.17.1"
+gem "jekyll", "4.1"
+
+gemspec path: "../"
diff --git a/jekyll-toc.gemspec b/jekyll-toc.gemspec
index a5ac286..4a1d53c 100644
--- a/jekyll-toc.gemspec
+++ b/jekyll-toc.gemspec
@@ -2,23 +2,23 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require 'version'
+require 'table_of_contents/version'
Gem::Specification.new do |spec|
- spec.name = 'jekyll-toc-navtotop'
- spec.version = JekyllToc::VERSION
- spec.summary = 'Jekyll Table of Contents plugin with navigation to top'
- spec.description = 'Jekyll (Ruby static website generator) plugin which generates a table of contents and a navigation to top.'
- spec.authors = ["n13.org", "KargWare", "N7K4", "toshimaru torbjoernk"]
- spec.email = 'rubygems.org@n13.org'
+ spec.name = 'jekyll-toc'
+ spec.version = Jekyll::TableOfContents::VERSION
+ spec.summary = 'Jekyll Table of Contents plugin'
+ spec.description = 'Jekyll (Ruby static website generator) plugin which generates a Table of Contents for the page.'
+ spec.authors = %w(toshimaru torbjoernk)
+ spec.email = 'me@toshimaru.net'
spec.files = `git ls-files -z`.split("\x0")
- spec.homepage = 'https://github.com/n13org/jekyll-toc-navtotop'
+ spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
spec.license = 'MIT'
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.4'
- spec.add_dependency 'jekyll', '>= 3.7'
- spec.add_dependency 'nokogiri', '~> 1.9'
+ spec.add_dependency 'jekyll', '>= 3.8'
+ spec.add_dependency 'nokogiri', '~> 1.10'
end
From fa9c46f8005a742a46d541d43a107708c32ae225 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Mon, 16 Nov 2020 14:30:48 +0100
Subject: [PATCH 28/29] Fix rubocop
---
lib/table_of_contents/parser.rb | 2 +-
test/parser/test_toc_filter.rb | 2 +-
test/parser/test_toc_only_filter_encoding.rb | 4 ++--
test/test_helper_encoding.rb | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index e2a4b1e..21890cb 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -23,7 +23,7 @@ def build_toc
end
def inject_anchors_into_html
- @entries.each do |entry|
+ @entries.each do |entry|
# NOTE: `entry[:id]` is automatically URL encoded by Nokogiri
entry[:header_content].add_previous_sibling(
%()
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index a398ae1..1324e98 100644
--- a/test/parser/test_toc_filter.rb
+++ b/test/parser/test_toc_filter.rb
@@ -31,6 +31,6 @@ def test_nested_toc
def test_injects_toc_container
html = @parser.toc
- assert_match(//, html)
+ assert_match(//, html)
end
end
diff --git a/test/parser/test_toc_only_filter_encoding.rb b/test/parser/test_toc_only_filter_encoding.rb
index 239a1d7..0c12ae3 100644
--- a/test/parser/test_toc_only_filter_encoding.rb
+++ b/test/parser/test_toc_only_filter_encoding.rb
@@ -6,7 +6,7 @@ class TestTOCOnlyFilterEncodingOn < Minitest::Test
include TestHelpersEncoding
def setup
- read_html_and_create_parser()
+ read_html_and_create_parser
end
def test_injects_toc_container_with_anchor_id_url_encoded
@@ -19,7 +19,7 @@ def test_injects_toc_container_with_anchor_id_url_encoded
assert_match(//, html)
assert_match(//, html)
assert_match(//, html)
- assert_match(//, html) # %C3%BC%C3%A4%C3%B6 --> ÜÄÖ
+ assert_match(//, html)
end
def test_does_not_return_content
diff --git a/test/test_helper_encoding.rb b/test/test_helper_encoding.rb
index 986a615..985342f 100644
--- a/test/test_helper_encoding.rb
+++ b/test/test_helper_encoding.rb
@@ -21,7 +21,7 @@
HTML
module TestHelpersEncoding
- def read_html_and_create_parser()
+ def read_html_and_create_parser
@parser = Jekyll::TableOfContents::Parser.new(SIMPLE_HTML_WITH_IDS)
@config = Jekyll::TableOfContents::Configuration.new({})
end
From 3fb1a9dc8b65ac4b90a0063187859093be1c32b1 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Mon, 16 Nov 2020 14:36:22 +0100
Subject: [PATCH 29/29] Disable some rubocops rules
---
.rubocop.yml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/.rubocop.yml b/.rubocop.yml
index 3abbf6b..53b5802 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -20,6 +20,8 @@ Metrics/ClassLength:
Naming/FileName:
Enabled: false
+Naming/VariableNumber:
+ Enabled: false
Layout/LineLength:
Enabled: false
@@ -41,3 +43,6 @@ Style/HashTransformValues:
Enabled: true
Style/ExponentialNotation:
Enabled: true
+
+Performance/StringInclude:
+ Enabled: false