jekyll-toc 0.17.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -2
- data/Appraisals +1 -1
- data/Gemfile +1 -1
- data/LICENSE.md +1 -1
- data/Rakefile +1 -1
- data/gemfiles/jekyll_3.9.gemfile +1 -1
- data/gemfiles/jekyll_4.0.gemfile +1 -1
- data/gemfiles/jekyll_4.1.gemfile +1 -1
- data/gemfiles/jekyll_4.2.gemfile +1 -1
- data/gemfiles/{jekyll_3.8.gemfile → jekyll_4.3.gemfile} +2 -2
- data/jekyll-toc.gemspec +17 -8
- data/lib/table_of_contents/version.rb +1 -1
- metadata +13 -36
- data/.github/dependabot.yml +0 -19
- data/.github/workflows/ci.yml +0 -27
- data/.github/workflows/coverage.yml +0 -22
- data/.github/workflows/rubocop.yml +0 -19
- data/.gitignore +0 -5
- data/test/parser/test_inject_anchors_filter.rb +0 -23
- data/test/parser/test_invalid_options.rb +0 -32
- data/test/parser/test_ordered_list.rb +0 -76
- data/test/parser/test_toc_filter.rb +0 -36
- data/test/parser/test_toc_only_filter.rb +0 -23
- data/test/parser/test_various_toc_html.rb +0 -376
- data/test/test_configuration.rb +0 -31
- data/test/test_helper.rb +0 -26
- data/test/test_jekyll-toc.rb +0 -52
- data/test/test_kramdown_list.rb +0 -168
- data/test/test_toc_tag.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b75ae0465d3a88244c85d2cb5c1476f0df77478747c69544d674a73f9de4f1
|
4
|
+
data.tar.gz: ce0e183c52b83c2a6ae717202f8fa009761c6e7272cc8b568acbcd737f415e5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61c5dee9b3bdde88cac5e5b86a0c6e15221ed0f552eb6bc6dc1bc81078834e9f14cd9ce7d43cd4184f379b5f59f1f81a72b2e32f6345a4d5a2037126267ec8b4
|
7
|
+
data.tar.gz: 3cfd49f3252395967f66166f48cbb5c899c694bf92465bf6deea9d55b9de4672353ae1a43c596cf281776c442b39804aeca5f464502675211c76ab759dda404a
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7
|
3
3
|
NewCops: enable
|
4
4
|
Exclude:
|
5
5
|
- "*.gemspec"
|
@@ -8,8 +8,9 @@ AllCops:
|
|
8
8
|
- Rakefile
|
9
9
|
- Gemfile
|
10
10
|
require:
|
11
|
-
- rubocop-performance
|
12
11
|
- rubocop-minitest
|
12
|
+
- rubocop-rake
|
13
|
+
- rubocop-performance
|
13
14
|
|
14
15
|
Metrics/MethodLength:
|
15
16
|
Enabled: false
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
data/Rakefile
CHANGED
data/gemfiles/jekyll_3.9.gemfile
CHANGED
data/gemfiles/jekyll_4.0.gemfile
CHANGED
data/gemfiles/jekyll_4.1.gemfile
CHANGED
data/gemfiles/jekyll_4.2.gemfile
CHANGED
data/jekyll-toc.gemspec
CHANGED
@@ -1,24 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'table_of_contents/version'
|
3
|
+
require_relative 'lib/table_of_contents/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |spec|
|
8
6
|
spec.name = 'jekyll-toc'
|
9
7
|
spec.version = Jekyll::TableOfContents::VERSION
|
10
8
|
spec.summary = 'Jekyll Table of Contents plugin'
|
11
9
|
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a Table of Contents for the page.'
|
12
|
-
spec.authors = %w
|
10
|
+
spec.authors = %w[toshimaru torbjoernk]
|
13
11
|
spec.email = 'me@toshimaru.net'
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
12
|
spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
|
16
13
|
spec.license = 'MIT'
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
18
14
|
spec.require_paths = ['lib']
|
19
15
|
|
20
|
-
spec.
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/toshimaru/jekyll-toc'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/toshimaru/jekyll-toc/releases'
|
19
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
spec.required_ruby_version = '>= 2.7'
|
21
30
|
|
22
31
|
spec.add_dependency 'jekyll', '>= 3.9'
|
23
|
-
spec.add_dependency 'nokogiri', '~> 1.
|
32
|
+
spec.add_dependency 'nokogiri', '~> 1.12'
|
24
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshimaru
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.12'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.12'
|
42
42
|
description: Jekyll (Ruby static website generator) plugin which generates a Table
|
43
43
|
of Contents for the page.
|
44
44
|
email: me@toshimaru.net
|
@@ -46,11 +46,6 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- ".github/dependabot.yml"
|
50
|
-
- ".github/workflows/ci.yml"
|
51
|
-
- ".github/workflows/coverage.yml"
|
52
|
-
- ".github/workflows/rubocop.yml"
|
53
|
-
- ".gitignore"
|
54
49
|
- ".rubocop.yml"
|
55
50
|
- Appraisals
|
56
51
|
- CHANGELOG.md
|
@@ -58,32 +53,25 @@ files:
|
|
58
53
|
- LICENSE.md
|
59
54
|
- README.md
|
60
55
|
- Rakefile
|
61
|
-
- gemfiles/jekyll_3.8.gemfile
|
62
56
|
- gemfiles/jekyll_3.9.gemfile
|
63
57
|
- gemfiles/jekyll_4.0.gemfile
|
64
58
|
- gemfiles/jekyll_4.1.gemfile
|
65
59
|
- gemfiles/jekyll_4.2.gemfile
|
60
|
+
- gemfiles/jekyll_4.3.gemfile
|
66
61
|
- jekyll-toc.gemspec
|
67
62
|
- lib/jekyll-toc.rb
|
68
63
|
- lib/table_of_contents/configuration.rb
|
69
64
|
- lib/table_of_contents/helper.rb
|
70
65
|
- lib/table_of_contents/parser.rb
|
71
66
|
- lib/table_of_contents/version.rb
|
72
|
-
- test/parser/test_inject_anchors_filter.rb
|
73
|
-
- test/parser/test_invalid_options.rb
|
74
|
-
- test/parser/test_ordered_list.rb
|
75
|
-
- test/parser/test_toc_filter.rb
|
76
|
-
- test/parser/test_toc_only_filter.rb
|
77
|
-
- test/parser/test_various_toc_html.rb
|
78
|
-
- test/test_configuration.rb
|
79
|
-
- test/test_helper.rb
|
80
|
-
- test/test_jekyll-toc.rb
|
81
|
-
- test/test_kramdown_list.rb
|
82
|
-
- test/test_toc_tag.rb
|
83
67
|
homepage: https://github.com/toshimaru/jekyll-toc
|
84
68
|
licenses:
|
85
69
|
- MIT
|
86
|
-
metadata:
|
70
|
+
metadata:
|
71
|
+
homepage_uri: https://github.com/toshimaru/jekyll-toc
|
72
|
+
source_code_uri: https://github.com/toshimaru/jekyll-toc
|
73
|
+
changelog_uri: https://github.com/toshimaru/jekyll-toc/releases
|
74
|
+
rubygems_mfa_required: 'true'
|
87
75
|
post_install_message:
|
88
76
|
rdoc_options: []
|
89
77
|
require_paths:
|
@@ -92,26 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
80
|
requirements:
|
93
81
|
- - ">="
|
94
82
|
- !ruby/object:Gem::Version
|
95
|
-
version: '2.
|
83
|
+
version: '2.7'
|
96
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
85
|
requirements:
|
98
86
|
- - ">="
|
99
87
|
- !ruby/object:Gem::Version
|
100
88
|
version: '0'
|
101
89
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.5.9
|
103
91
|
signing_key:
|
104
92
|
specification_version: 4
|
105
93
|
summary: Jekyll Table of Contents plugin
|
106
|
-
test_files:
|
107
|
-
- test/parser/test_inject_anchors_filter.rb
|
108
|
-
- test/parser/test_invalid_options.rb
|
109
|
-
- test/parser/test_ordered_list.rb
|
110
|
-
- test/parser/test_toc_filter.rb
|
111
|
-
- test/parser/test_toc_only_filter.rb
|
112
|
-
- test/parser/test_various_toc_html.rb
|
113
|
-
- test/test_configuration.rb
|
114
|
-
- test/test_helper.rb
|
115
|
-
- test/test_jekyll-toc.rb
|
116
|
-
- test/test_kramdown_list.rb
|
117
|
-
- test/test_toc_tag.rb
|
94
|
+
test_files: []
|
data/.github/dependabot.yml
DELETED
@@ -1,19 +0,0 @@
|
|
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
|
data/.github/workflows/ci.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
name: CI
|
2
|
-
on: [push, pull_request]
|
3
|
-
jobs:
|
4
|
-
build:
|
5
|
-
strategy:
|
6
|
-
matrix:
|
7
|
-
ruby: [2.5, 2.6, 2.7, 3.0]
|
8
|
-
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
|
13
|
-
env:
|
14
|
-
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
steps:
|
17
|
-
- uses: actions/checkout@v2
|
18
|
-
- name: Set up Ruby ${{ matrix.ruby }}
|
19
|
-
uses: ruby/setup-ruby@v1
|
20
|
-
with:
|
21
|
-
ruby-version: ${{ matrix.ruby }}
|
22
|
-
- name: bundle install
|
23
|
-
run: |
|
24
|
-
gem install bundler
|
25
|
-
bundle install --jobs 4 --retry 3
|
26
|
-
- name: Run Test
|
27
|
-
run: bundle exec rake
|
@@ -1,22 +0,0 @@
|
|
1
|
-
name: Coverage
|
2
|
-
on: [push, pull_request]
|
3
|
-
jobs:
|
4
|
-
build:
|
5
|
-
strategy:
|
6
|
-
matrix:
|
7
|
-
ruby: [3.0]
|
8
|
-
runs-on: ubuntu-latest
|
9
|
-
name: coverage
|
10
|
-
steps:
|
11
|
-
- uses: actions/checkout@v2
|
12
|
-
- name: Set up Ruby ${{ matrix.ruby }}
|
13
|
-
uses: ruby/setup-ruby@v1
|
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.7.5
|
19
|
-
env:
|
20
|
-
CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
|
21
|
-
with:
|
22
|
-
coverageCommand: bundle exec rake
|
@@ -1,19 +0,0 @@
|
|
1
|
-
name: RuboCop
|
2
|
-
on: [push, pull_request]
|
3
|
-
jobs:
|
4
|
-
build:
|
5
|
-
strategy:
|
6
|
-
matrix:
|
7
|
-
ruby: [3.0]
|
8
|
-
runs-on: ubuntu-latest
|
9
|
-
name: rubocop
|
10
|
-
steps:
|
11
|
-
- uses: actions/checkout@v2
|
12
|
-
- name: Set up Ruby ${{ matrix.ruby }}
|
13
|
-
uses: ruby/setup-ruby@v1
|
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/.gitignore
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestInjectAnchorsFilter < Minitest::Test
|
6
|
-
include TestHelpers
|
7
|
-
|
8
|
-
def setup
|
9
|
-
read_html_and_create_parser
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_injects_anchors_into_content
|
13
|
-
html = @parser.inject_anchors_into_html
|
14
|
-
|
15
|
-
assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_does_not_inject_toc
|
19
|
-
html = @parser.inject_anchors_into_html
|
20
|
-
|
21
|
-
refute_includes(html, %(<ul id="toc" class="section-nav">))
|
22
|
-
end
|
23
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestInvalidOptions < Minitest::Test
|
6
|
-
BASE_HTML = '<h1>h1</h1>'
|
7
|
-
EXPECTED_HTML = <<~HTML.chomp
|
8
|
-
<ul id="toc" class="section-nav">
|
9
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
10
|
-
</ul>
|
11
|
-
HTML
|
12
|
-
|
13
|
-
def test_option_is_nil
|
14
|
-
parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, nil)
|
15
|
-
assert_equal(EXPECTED_HTML, parser.build_toc)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_option_is_epmty_string
|
19
|
-
parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, '')
|
20
|
-
assert_equal(EXPECTED_HTML, parser.build_toc)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_option_is_string
|
24
|
-
parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, 'string')
|
25
|
-
assert_equal(EXPECTED_HTML, parser.build_toc)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_option_is_array
|
29
|
-
parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, [])
|
30
|
-
assert_equal(EXPECTED_HTML, parser.build_toc)
|
31
|
-
end
|
32
|
-
end
|
@@ -1,76 +0,0 @@
|
|
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
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestTOCFilter < Minitest::Test
|
6
|
-
include TestHelpers
|
7
|
-
|
8
|
-
def setup
|
9
|
-
read_html_and_create_parser
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_injects_anchors
|
13
|
-
html = @parser.toc
|
14
|
-
|
15
|
-
assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_nested_toc
|
19
|
-
doc = Nokogiri::HTML(@parser.toc)
|
20
|
-
nested_h6_text = doc.css('ul.section-nav')
|
21
|
-
.css('li.toc-h1')
|
22
|
-
.css('li.toc-h2')
|
23
|
-
.css('li.toc-h3')
|
24
|
-
.css('li.toc-h4')
|
25
|
-
.css('li.toc-h5')
|
26
|
-
.css('li.toc-h6')
|
27
|
-
.text
|
28
|
-
assert_equal('Simple H6', nested_h6_text)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_injects_toc_container
|
32
|
-
html = @parser.toc
|
33
|
-
|
34
|
-
assert_match(/<ul id="toc" class="section-nav">/, html)
|
35
|
-
end
|
36
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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, %(<ul id="toc" class="section-nav">))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_does_not_return_content
|
19
|
-
html = @parser.build_toc
|
20
|
-
|
21
|
-
refute_includes(html, %(<h1>Simple H1</h1>))
|
22
|
-
end
|
23
|
-
end
|
@@ -1,376 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestVariousTocHtml < Minitest::Test
|
6
|
-
TEST_HTML = <<~HTML
|
7
|
-
<h1>h1</h1>
|
8
|
-
<h3>h3</h3>
|
9
|
-
<h6>h6</h6>
|
10
|
-
HTML
|
11
|
-
|
12
|
-
def test_nested_toc
|
13
|
-
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML)
|
14
|
-
expected = <<~HTML.chomp
|
15
|
-
<ul id="toc" class="section-nav">
|
16
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
17
|
-
<ul>
|
18
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
19
|
-
<ul>
|
20
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
21
|
-
</ul>
|
22
|
-
</li>
|
23
|
-
</ul>
|
24
|
-
</li>
|
25
|
-
</ul>
|
26
|
-
HTML
|
27
|
-
|
28
|
-
assert_equal(expected, parser.build_toc)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_nested_toc_with_min_and_max
|
32
|
-
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML, 'min_level' => 2, 'max_level' => 5)
|
33
|
-
expected = <<~HTML.chomp
|
34
|
-
<ul id="toc" class="section-nav">
|
35
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
36
|
-
</ul>
|
37
|
-
HTML
|
38
|
-
|
39
|
-
assert_equal(expected, parser.build_toc)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_complex_nested_toc
|
43
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
44
|
-
<h1>h1</h1>
|
45
|
-
<h3>h3</h3>
|
46
|
-
<h2>h2</h2>
|
47
|
-
<h6>h6</h6>
|
48
|
-
HTML
|
49
|
-
expected = <<~HTML.chomp
|
50
|
-
<ul id="toc" class="section-nav">
|
51
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
52
|
-
<ul>
|
53
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
54
|
-
<li class="toc-entry toc-h2"><a href="#h2">h2</a>
|
55
|
-
<ul>
|
56
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
57
|
-
</ul>
|
58
|
-
</li>
|
59
|
-
</ul>
|
60
|
-
</li>
|
61
|
-
</ul>
|
62
|
-
HTML
|
63
|
-
|
64
|
-
assert_equal(expected, parser.build_toc)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_decremental_headings1
|
68
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
69
|
-
<h6>h6</h6>
|
70
|
-
<h5>h5</h5>
|
71
|
-
<h4>h4</h4>
|
72
|
-
<h3>h3</h3>
|
73
|
-
<h2>h2</h2>
|
74
|
-
<h1>h1</h1>
|
75
|
-
HTML
|
76
|
-
expected = <<~HTML.chomp
|
77
|
-
<ul id="toc" class="section-nav">
|
78
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
79
|
-
<li class="toc-entry toc-h5"><a href="#h5">h5</a></li>
|
80
|
-
<li class="toc-entry toc-h4"><a href="#h4">h4</a></li>
|
81
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
82
|
-
<li class="toc-entry toc-h2"><a href="#h2">h2</a></li>
|
83
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
84
|
-
</ul>
|
85
|
-
HTML
|
86
|
-
|
87
|
-
assert_equal(expected, parser.build_toc)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_decremental_headings2
|
91
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
92
|
-
<h1>h1</h1>
|
93
|
-
<h3>h3</h3>
|
94
|
-
<h2>h2</h2>
|
95
|
-
<h4>h4</h4>
|
96
|
-
<h5>h5</h5>
|
97
|
-
HTML
|
98
|
-
expected = <<~HTML.chomp
|
99
|
-
<ul id="toc" class="section-nav">
|
100
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
101
|
-
<ul>
|
102
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a></li>
|
103
|
-
<li class="toc-entry toc-h2"><a href="#h2">h2</a>
|
104
|
-
<ul>
|
105
|
-
<li class="toc-entry toc-h4"><a href="#h4">h4</a>
|
106
|
-
<ul>
|
107
|
-
<li class="toc-entry toc-h5"><a href="#h5">h5</a></li>
|
108
|
-
</ul>
|
109
|
-
</li>
|
110
|
-
</ul>
|
111
|
-
</li>
|
112
|
-
</ul>
|
113
|
-
</li>
|
114
|
-
</ul>
|
115
|
-
HTML
|
116
|
-
|
117
|
-
assert_equal(expected, parser.build_toc)
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_no_toc
|
121
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
122
|
-
<h1>h1</h1>
|
123
|
-
<h1 class="no_toc">no_toc h1</h1>
|
124
|
-
<h2>h2</h2>
|
125
|
-
<h2 class="no_toc">no_toc h2</h2>
|
126
|
-
<h3>h3</h3>
|
127
|
-
<h3 class="no_toc">no_toc h3</h3>
|
128
|
-
<h4>h4</h4>
|
129
|
-
<h4 class="no_toc">no_toc h4</h4>
|
130
|
-
HTML
|
131
|
-
expected = <<~HTML.chomp
|
132
|
-
<ul id="toc" class="section-nav">
|
133
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
134
|
-
<ul>
|
135
|
-
<li class="toc-entry toc-h2"><a href="#h2">h2</a>
|
136
|
-
<ul>
|
137
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
138
|
-
<ul>
|
139
|
-
<li class="toc-entry toc-h4"><a href="#h4">h4</a></li>
|
140
|
-
</ul>
|
141
|
-
</li>
|
142
|
-
</ul>
|
143
|
-
</li>
|
144
|
-
</ul>
|
145
|
-
</li>
|
146
|
-
</ul>
|
147
|
-
HTML
|
148
|
-
|
149
|
-
assert_equal(expected, parser.build_toc)
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_japanese_toc
|
153
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
154
|
-
<h1>あ</h1>
|
155
|
-
<h2>い</h2>
|
156
|
-
<h3>う</h3>
|
157
|
-
HTML
|
158
|
-
expected = <<~HTML.chomp
|
159
|
-
<ul id="toc" class="section-nav">
|
160
|
-
<li class="toc-entry toc-h1"><a href="#%E3%81%82">あ</a>
|
161
|
-
<ul>
|
162
|
-
<li class="toc-entry toc-h2"><a href="#%E3%81%84">い</a>
|
163
|
-
<ul>
|
164
|
-
<li class="toc-entry toc-h3"><a href="#%E3%81%86">う</a></li>
|
165
|
-
</ul>
|
166
|
-
</li>
|
167
|
-
</ul>
|
168
|
-
</li>
|
169
|
-
</ul>
|
170
|
-
HTML
|
171
|
-
|
172
|
-
assert_equal(expected, parser.build_toc)
|
173
|
-
html_with_anchors = parser.inject_anchors_into_html
|
174
|
-
assert_match(%r{<a class="anchor" href="#%E3%81%82" aria-hidden="true"><span.*span></a>あ}, html_with_anchors)
|
175
|
-
assert_match(%r{<a class="anchor" href="#%E3%81%84" aria-hidden="true"><span.*span></a>い}, html_with_anchors)
|
176
|
-
assert_match(%r{<a class="anchor" href="#%E3%81%86" aria-hidden="true"><span.*span></a>う}, html_with_anchors)
|
177
|
-
end
|
178
|
-
|
179
|
-
# ref. https://github.com/toshimaru/jekyll-toc/issues/45
|
180
|
-
def test_angle_bracket
|
181
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
182
|
-
<h1>h1</h1>
|
183
|
-
<h1><base href></h1>
|
184
|
-
<h1>& < ></h1>
|
185
|
-
HTML
|
186
|
-
expected = <<~HTML.chomp
|
187
|
-
<ul id="toc" class="section-nav">
|
188
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
189
|
-
<li class="toc-entry toc-h1"><a href="#base-href"><base href></a></li>
|
190
|
-
<li class="toc-entry toc-h1"><a href="#--">& < ></a></li>
|
191
|
-
</ul>
|
192
|
-
HTML
|
193
|
-
|
194
|
-
assert_equal(expected, parser.build_toc)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_tags_inside_heading
|
198
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
199
|
-
<h2><strong>h2</strong></h2>
|
200
|
-
<h2><em>h2</em></h2>
|
201
|
-
HTML
|
202
|
-
expected = <<~HTML.chomp
|
203
|
-
<ul id="toc" class="section-nav">
|
204
|
-
<li class="toc-entry toc-h2"><a href="#h2">h2</a></li>
|
205
|
-
<li class="toc-entry toc-h2"><a href="#h2-1">h2</a></li>
|
206
|
-
</ul>
|
207
|
-
HTML
|
208
|
-
|
209
|
-
assert_equal(expected, parser.build_toc)
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_nested_toc_with_no_toc_section_class
|
213
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
214
|
-
<h1>h1</h1>
|
215
|
-
<div class="no_toc_section">
|
216
|
-
<h2>h2</h2>
|
217
|
-
</div>
|
218
|
-
<h3>h3</h3>
|
219
|
-
<h6>h6</h6>
|
220
|
-
HTML
|
221
|
-
expected = <<~HTML.chomp
|
222
|
-
<ul id="toc" class="section-nav">
|
223
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
224
|
-
<ul>
|
225
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
226
|
-
<ul>
|
227
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
228
|
-
</ul>
|
229
|
-
</li>
|
230
|
-
</ul>
|
231
|
-
</li>
|
232
|
-
</ul>
|
233
|
-
HTML
|
234
|
-
assert_equal(expected, parser.build_toc)
|
235
|
-
|
236
|
-
html = parser.inject_anchors_into_html
|
237
|
-
assert_match(%r{<h1>.+</h1>}m, html)
|
238
|
-
assert_match(%r{<h3>.+</h3>}m, html)
|
239
|
-
assert_match(%r{<h6>.+</h6>}m, html)
|
240
|
-
assert_includes(html, '<h2>h2</h2>')
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_nested_toc_with_no_toc_section_class_option
|
244
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML, 'no_toc_section_class' => 'exclude')
|
245
|
-
<h1>h1</h1>
|
246
|
-
<div class="exclude">
|
247
|
-
<h2>h2</h2>
|
248
|
-
</div>
|
249
|
-
<h3>h3</h3>
|
250
|
-
<div class="exclude">
|
251
|
-
<h4>h4</h4>
|
252
|
-
<h5>h5</h5>
|
253
|
-
</div>
|
254
|
-
<h6>h6</h6>
|
255
|
-
HTML
|
256
|
-
expected = <<~HTML.chomp
|
257
|
-
<ul id="toc" class="section-nav">
|
258
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
259
|
-
<ul>
|
260
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
261
|
-
<ul>
|
262
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
263
|
-
</ul>
|
264
|
-
</li>
|
265
|
-
</ul>
|
266
|
-
</li>
|
267
|
-
</ul>
|
268
|
-
HTML
|
269
|
-
assert_equal(expected, parser.build_toc)
|
270
|
-
|
271
|
-
html = parser.inject_anchors_into_html
|
272
|
-
assert_match(%r{<h1>.+</h1>}m, html)
|
273
|
-
assert_match(%r{<h3>.+</h3>}m, html)
|
274
|
-
assert_match(%r{<h6>.+</h6>}m, html)
|
275
|
-
assert_includes(html, '<h2>h2</h2>')
|
276
|
-
assert_includes(html, '<h4>h4</h4>')
|
277
|
-
assert_includes(html, '<h5>h5</h5>')
|
278
|
-
end
|
279
|
-
|
280
|
-
def test_multiple_no_toc_section_classes
|
281
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML, 'no_toc_section_class' => ['no_toc_section', 'exclude'])
|
282
|
-
<h1>h1</h1>
|
283
|
-
<div class="no_toc_section">
|
284
|
-
<h2>h2</h2>
|
285
|
-
</div>
|
286
|
-
<h3>h3</h3>
|
287
|
-
<div class="exclude">
|
288
|
-
<h4>h4</h4>
|
289
|
-
<h5>h5</h5>
|
290
|
-
</div>
|
291
|
-
<h6>h6</h6>
|
292
|
-
HTML
|
293
|
-
expected = <<~HTML.chomp
|
294
|
-
<ul id="toc" class="section-nav">
|
295
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a>
|
296
|
-
<ul>
|
297
|
-
<li class="toc-entry toc-h3"><a href="#h3">h3</a>
|
298
|
-
<ul>
|
299
|
-
<li class="toc-entry toc-h6"><a href="#h6">h6</a></li>
|
300
|
-
</ul>
|
301
|
-
</li>
|
302
|
-
</ul>
|
303
|
-
</li>
|
304
|
-
</ul>
|
305
|
-
HTML
|
306
|
-
assert_equal(expected, parser.build_toc)
|
307
|
-
|
308
|
-
html = parser.inject_anchors_into_html
|
309
|
-
assert_match(%r{<h1>.+</h1>}m, html)
|
310
|
-
assert_match(%r{<h3>.+</h3>}m, html)
|
311
|
-
assert_match(%r{<h6>.+</h6>}m, html)
|
312
|
-
assert_includes(html, '<h2>h2</h2>')
|
313
|
-
assert_includes(html, '<h4>h4</h4>')
|
314
|
-
assert_includes(html, '<h5>h5</h5>')
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_toc_with_explicit_id
|
318
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
319
|
-
<h1>h1</h1>
|
320
|
-
<h1 id="second">h2</h1>
|
321
|
-
<h1 id="third">h3</h1>
|
322
|
-
HTML
|
323
|
-
expected = <<~HTML.chomp
|
324
|
-
<ul id="toc" class="section-nav">
|
325
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
326
|
-
<li class="toc-entry toc-h1"><a href="#second">h2</a></li>
|
327
|
-
<li class="toc-entry toc-h1"><a href="#third">h3</a></li>
|
328
|
-
</ul>
|
329
|
-
HTML
|
330
|
-
assert_equal(expected, parser.build_toc)
|
331
|
-
|
332
|
-
html = parser.inject_anchors_into_html
|
333
|
-
assert_includes(html, %(<a class="anchor" href="#h1" aria-hidden="true">))
|
334
|
-
assert_includes(html, %(<a class="anchor" href="#second" aria-hidden="true">))
|
335
|
-
assert_includes(html, %(<a class="anchor" href="#third" aria-hidden="true">))
|
336
|
-
end
|
337
|
-
|
338
|
-
def test_anchor_is_uniq
|
339
|
-
parser = Jekyll::TableOfContents::Parser.new(<<~HTML)
|
340
|
-
<h1>h1</h1>
|
341
|
-
<h1>h1</h1>
|
342
|
-
<h1>h1</h1>
|
343
|
-
HTML
|
344
|
-
expected = <<~HTML.chomp
|
345
|
-
<ul id="toc" class="section-nav">
|
346
|
-
<li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
|
347
|
-
<li class="toc-entry toc-h1"><a href="#h1-1">h1</a></li>
|
348
|
-
<li class="toc-entry toc-h1"><a href="#h1-2">h1</a></li>
|
349
|
-
</ul>
|
350
|
-
HTML
|
351
|
-
|
352
|
-
assert_equal(expected, parser.build_toc)
|
353
|
-
end
|
354
|
-
|
355
|
-
def test_custom_css_classes
|
356
|
-
parser = Jekyll::TableOfContents::Parser.new(
|
357
|
-
TEST_HTML,
|
358
|
-
'item_class' => 'custom-item', 'list_id' => 'custom-toc-id', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
|
359
|
-
)
|
360
|
-
expected = <<~HTML.chomp
|
361
|
-
<ul id="custom-toc-id" class="custom-list">
|
362
|
-
<li class="custom-item custom-prefix-h1"><a href="#h1">h1</a>
|
363
|
-
<ul class="custom-sublist">
|
364
|
-
<li class="custom-item custom-prefix-h3"><a href="#h3">h3</a>
|
365
|
-
<ul class="custom-sublist">
|
366
|
-
<li class="custom-item custom-prefix-h6"><a href="#h6">h6</a></li>
|
367
|
-
</ul>
|
368
|
-
</li>
|
369
|
-
</ul>
|
370
|
-
</li>
|
371
|
-
</ul>
|
372
|
-
HTML
|
373
|
-
|
374
|
-
assert_equal(expected, parser.build_toc)
|
375
|
-
end
|
376
|
-
end
|
data/test/test_configuration.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestConfiguration < Minitest::Test
|
6
|
-
def test_default_configuration
|
7
|
-
configuration = Jekyll::TableOfContents::Configuration.new({})
|
8
|
-
|
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)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_type_error
|
20
|
-
configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
|
21
|
-
|
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)
|
30
|
-
end
|
31
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
SimpleCov.start
|
5
|
-
|
6
|
-
require 'minitest/autorun'
|
7
|
-
require 'minitest/reporters'
|
8
|
-
Minitest::Reporters.use!
|
9
|
-
|
10
|
-
require 'jekyll'
|
11
|
-
require 'jekyll-toc'
|
12
|
-
|
13
|
-
SIMPLE_HTML = <<~HTML
|
14
|
-
<h1>Simple H1</h1>
|
15
|
-
<h2>Simple H2</h2>
|
16
|
-
<h3>Simple H3</h3>
|
17
|
-
<h4>Simple H4</h4>
|
18
|
-
<h5>Simple H5</h5>
|
19
|
-
<h6>Simple H6</h6>
|
20
|
-
HTML
|
21
|
-
|
22
|
-
module TestHelpers
|
23
|
-
def read_html_and_create_parser(options = {})
|
24
|
-
@parser = Jekyll::TableOfContents::Parser.new(SIMPLE_HTML, options)
|
25
|
-
end
|
26
|
-
end
|
data/test/test_jekyll-toc.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestTableOfContentsFilter < Minitest::Test
|
6
|
-
include Jekyll::TableOfContentsFilter
|
7
|
-
|
8
|
-
DUMMY_HTML = '<div>Dummy HTML Content</div>'
|
9
|
-
|
10
|
-
def test_toc_only
|
11
|
-
@context = disable_toc_context
|
12
|
-
assert_empty toc_only(DUMMY_HTML)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_inject_anchors
|
16
|
-
@context = disable_toc_context
|
17
|
-
assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_toc
|
21
|
-
@context = disable_toc_context
|
22
|
-
assert_equal DUMMY_HTML, toc(DUMMY_HTML)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_toc_only2
|
26
|
-
@context = enable_toc_context
|
27
|
-
assert_equal %(<ul id="toc" class="section-nav">\n</ul>), toc_only(DUMMY_HTML)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_inject_anchors2
|
31
|
-
@context = enable_toc_context
|
32
|
-
assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_toc2
|
36
|
-
@context = enable_toc_context
|
37
|
-
assert_equal %(<ul id="toc" class="section-nav">\n</ul>#{DUMMY_HTML}), toc(DUMMY_HTML)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def disable_toc_context
|
43
|
-
Struct.new(:registers).new(page: { 'toc' => false })
|
44
|
-
end
|
45
|
-
|
46
|
-
def enable_toc_context
|
47
|
-
Struct.new(:registers).new(
|
48
|
-
page: { 'toc' => true },
|
49
|
-
site: Struct.new(:config).new({ 'toc' => false })
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
data/test/test_kramdown_list.rb
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestKramdownList < Minitest::Test
|
6
|
-
# NOTE: kramdown automatically injects `id` attribute
|
7
|
-
def test_kramdown_heading
|
8
|
-
text = <<~MARKDOWN
|
9
|
-
# h1
|
10
|
-
|
11
|
-
## h2
|
12
|
-
MARKDOWN
|
13
|
-
expected = <<~HTML
|
14
|
-
<h1 id="h1">h1</h1>
|
15
|
-
|
16
|
-
<h2 id="h2">h2</h2>
|
17
|
-
HTML
|
18
|
-
actual = Kramdown::Document.new(text).to_html
|
19
|
-
|
20
|
-
assert_equal(expected, actual)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_japanese_heading
|
24
|
-
text = <<~MARKDOWN
|
25
|
-
# 日本語見出し1
|
26
|
-
|
27
|
-
## 日本語見出し2
|
28
|
-
MARKDOWN
|
29
|
-
expected = <<~HTML
|
30
|
-
<h1 id="section">日本語見出し1</h1>
|
31
|
-
|
32
|
-
<h2 id="section-1">日本語見出し2</h2>
|
33
|
-
HTML
|
34
|
-
actual = Kramdown::Document.new(text).to_html
|
35
|
-
|
36
|
-
assert_equal(expected, actual)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_kramdown_list_l1_l5
|
40
|
-
text = <<~MARKDOWN
|
41
|
-
* level-1
|
42
|
-
* level-2
|
43
|
-
* level-3
|
44
|
-
* level-4
|
45
|
-
* level-5
|
46
|
-
MARKDOWN
|
47
|
-
expected = <<~HTML
|
48
|
-
<ul>
|
49
|
-
<li>level-1
|
50
|
-
<ul>
|
51
|
-
<li>level-2
|
52
|
-
<ul>
|
53
|
-
<li>level-3
|
54
|
-
<ul>
|
55
|
-
<li>level-4
|
56
|
-
<ul>
|
57
|
-
<li>level-5</li>
|
58
|
-
</ul>
|
59
|
-
</li>
|
60
|
-
</ul>
|
61
|
-
</li>
|
62
|
-
</ul>
|
63
|
-
</li>
|
64
|
-
</ul>
|
65
|
-
</li>
|
66
|
-
</ul>
|
67
|
-
HTML
|
68
|
-
actual = Kramdown::Document.new(text).to_html
|
69
|
-
|
70
|
-
assert_equal(expected, actual)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_kramdown_list_l1_l3_l2_l4
|
74
|
-
text = <<~MARKDOWN
|
75
|
-
* level-1
|
76
|
-
* level-3
|
77
|
-
* level-2
|
78
|
-
* level-4
|
79
|
-
* level-5
|
80
|
-
MARKDOWN
|
81
|
-
expected = <<~HTML
|
82
|
-
<ul>
|
83
|
-
<li>level-1
|
84
|
-
<ul>
|
85
|
-
<li>level-3</li>
|
86
|
-
<li>level-2
|
87
|
-
<ul>
|
88
|
-
<li>level-4
|
89
|
-
<ul>
|
90
|
-
<li>level-5</li>
|
91
|
-
</ul>
|
92
|
-
</li>
|
93
|
-
</ul>
|
94
|
-
</li>
|
95
|
-
</ul>
|
96
|
-
</li>
|
97
|
-
</ul>
|
98
|
-
HTML
|
99
|
-
actual = Kramdown::Document.new(text).to_html
|
100
|
-
|
101
|
-
assert_equal(expected, actual)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_kramdown_list_l4_l1
|
105
|
-
text = <<~MARKDOWN
|
106
|
-
* level-4
|
107
|
-
* level-3
|
108
|
-
* level-2
|
109
|
-
* level-1
|
110
|
-
MARKDOWN
|
111
|
-
expected = <<~HTML
|
112
|
-
<pre><code> * level-4
|
113
|
-
* level-3 * level-2 * level-1
|
114
|
-
</code></pre>
|
115
|
-
HTML
|
116
|
-
actual = Kramdown::Document.new(text).to_html
|
117
|
-
|
118
|
-
assert_equal(expected, actual)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_kramdown_list_l1_l4_l1
|
122
|
-
text = <<~MARKDOWN
|
123
|
-
* level-1
|
124
|
-
* level-4
|
125
|
-
* level-3
|
126
|
-
* level-2
|
127
|
-
* level-1
|
128
|
-
MARKDOWN
|
129
|
-
expected = <<~HTML
|
130
|
-
<ul>
|
131
|
-
<li>level-1
|
132
|
-
* level-4
|
133
|
-
<ul>
|
134
|
-
<li>level-3</li>
|
135
|
-
<li>level-2</li>
|
136
|
-
</ul>
|
137
|
-
</li>
|
138
|
-
<li>level-1</li>
|
139
|
-
</ul>
|
140
|
-
HTML
|
141
|
-
actual = Kramdown::Document.new(text).to_html
|
142
|
-
|
143
|
-
assert_equal(expected, actual)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_kramdown_list_l1_l3_l1
|
147
|
-
text = <<~MARKDOWN
|
148
|
-
* level-1
|
149
|
-
* level-3
|
150
|
-
* level-2
|
151
|
-
* level-1
|
152
|
-
MARKDOWN
|
153
|
-
expected = <<~HTML
|
154
|
-
<ul>
|
155
|
-
<li>level-1
|
156
|
-
<ul>
|
157
|
-
<li>level-3</li>
|
158
|
-
<li>level-2</li>
|
159
|
-
</ul>
|
160
|
-
</li>
|
161
|
-
<li>level-1</li>
|
162
|
-
</ul>
|
163
|
-
HTML
|
164
|
-
actual = Kramdown::Document.new(text).to_html
|
165
|
-
|
166
|
-
assert_equal(expected, actual)
|
167
|
-
end
|
168
|
-
end
|
data/test/test_toc_tag.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestTableOfContentsTag < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@stubbed_context = Struct.new(:registers)
|
10
|
-
@stubbed_context1 = Struct.new(:config)
|
11
|
-
@stubbed_context2 = Struct.new(:toc, :content)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_toc_tag
|
15
|
-
context = @stubbed_context.new(
|
16
|
-
page: @stubbed_context2.new({ 'toc' => false }, '<h1>test</h1>'),
|
17
|
-
site: @stubbed_context1.new({ 'toc' => nil })
|
18
|
-
)
|
19
|
-
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
|
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
|
-
end
|
22
|
-
|
23
|
-
def test_toc_tag_returns_empty_string
|
24
|
-
context = @stubbed_context.new(page: { 'toc' => false })
|
25
|
-
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
|
26
|
-
assert_empty tag.render(context)
|
27
|
-
end
|
28
|
-
end
|