├── .gitignore ├── CHANGELOG.md ├── lib ├── table_of_contents │ ├── version.rb │ ├── helper.rb │ ├── configuration.rb │ └── parser.rb └── jekyll-toc.rb ├── Appraisals ├── Rakefile ├── Gemfile ├── gemfiles ├── jekyll_3.9.gemfile ├── jekyll_4.0.gemfile ├── jekyll_4.1.gemfile ├── jekyll_4.2.gemfile └── jekyll_4.3.gemfile ├── .github ├── workflows │ ├── rubocop.yml │ ├── coverage.yml │ └── ci.yml └── dependabot.yml ├── test ├── parser │ ├── test_toc_only_filter.rb │ ├── test_inject_anchors_filter.rb │ ├── test_invalid_options.rb │ ├── test_toc_filter.rb │ ├── test_ordered_list.rb │ └── test_various_toc_html.rb ├── test_helper.rb ├── test_toc_tag.rb ├── test_configuration.rb ├── test_jekyll-toc.rb └── test_kramdown_list.rb ├── .rubocop.yml ├── LICENSE.md ├── jekyll-toc.gemspec └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | /Gemfile.lock 3 | /.bundle/ 4 | /coverage 5 | *.gemfile.lock 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog is maintained under [Github Releases](https://github.com/toshimaru/jekyll-toc/releases). 2 | -------------------------------------------------------------------------------- /lib/table_of_contents/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Jekyll 4 | module TableOfContents 5 | VERSION = '0.19.0' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | SUPPORTED_VERSIONS = %w[3.9 4.0 4.1 4.2 4.3].freeze 4 | 5 | SUPPORTED_VERSIONS.each do |version| 6 | appraise "jekyll-#{version}" do 7 | gem 'jekyll', version 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | task default: :test 4 | 5 | require 'rake/testtask' 6 | Rake::TestTask.new(:test) do |test| 7 | test.libs << 'lib' << 'test' 8 | test.pattern = 'test/**/test_*.rb' 9 | test.verbose = true 10 | end 11 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 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.22.0' 15 | -------------------------------------------------------------------------------- /gemfiles/jekyll_3.9.gemfile: -------------------------------------------------------------------------------- 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.22.0" 15 | gem "jekyll", "3.9" 16 | 17 | gemspec path: "../" 18 | -------------------------------------------------------------------------------- /gemfiles/jekyll_4.0.gemfile: -------------------------------------------------------------------------------- 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.22.0" 15 | gem "jekyll", "4.0" 16 | 17 | gemspec path: "../" 18 | -------------------------------------------------------------------------------- /gemfiles/jekyll_4.1.gemfile: -------------------------------------------------------------------------------- 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.22.0" 15 | gem "jekyll", "4.1" 16 | 17 | gemspec path: "../" 18 | -------------------------------------------------------------------------------- /gemfiles/jekyll_4.2.gemfile: -------------------------------------------------------------------------------- 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.22.0" 15 | gem "jekyll", "4.2" 16 | 17 | gemspec path: "../" 18 | -------------------------------------------------------------------------------- /gemfiles/jekyll_4.3.gemfile: -------------------------------------------------------------------------------- 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.22.0" 15 | gem "jekyll", "4.3" 16 | 17 | gemspec path: "../" 18 | -------------------------------------------------------------------------------- /.github/workflows/rubocop.yml: -------------------------------------------------------------------------------- 1 | name: RuboCop 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | rubocop: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Set up Ruby 15 | uses: ruby/setup-ruby@v1 16 | with: 17 | ruby-version: 3.2 18 | bundler-cache: true 19 | - name: Run RuboCop 20 | run: bundle exec rubocop 21 | -------------------------------------------------------------------------------- /lib/table_of_contents/helper.rb: -------------------------------------------------------------------------------- 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 18 | -------------------------------------------------------------------------------- /test/parser/test_toc_only_filter.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'test_helper' 4 | 5 | class TestTOCOnlyFilter < Minitest::Test 6 | include TestHelpers 7 | 8 | def setup 9 | read_html_and_create_parser 10 | end 11 | 12 | def test_injects_toc_container 13 | html = @parser.build_toc 14 | 15 | assert_includes(html, %(