diff --git a/.gitignore b/.gitignore
index 3573f4a..7bdc6ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,20 @@
+# gems
*.gem
/Gemfile.lock
-/.bundle/
-/coverage
*.gemfile.lock
+/gems/
+
+# local gem package folder
+/pkg/
+
+# tests / test coverage
+.jekyll-cache/
+/coverage
+
+# bundler
+/.bundle/
+/vendor/bundle/
+/gemfiles/.bundle/
+/gemfiles/vendor/bundle/
+
+# unsorted
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
diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb
index aa6a9c4..89529f5 100644
--- a/lib/table_of_contents/configuration.rb
+++ b/lib/table_of_contents/configuration.rb
@@ -5,17 +5,20 @@ module TableOfContents
# jekyll-toc configuration class
class Configuration
attr_reader :toc_levels, :no_toc_class, :ordered_list, :no_toc_section_class,
- :list_class, :sublist_class, :item_class, :item_prefix
+ :list_id, :list_class, :sublist_class, :item_class, :item_prefix,
+ :nav_to_toc_symbol
DEFAULT_CONFIG = {
'min_level' => 1,
'max_level' => 6,
'ordered_list' => false,
'no_toc_section_class' => 'no_toc_section',
+ 'list_id' => 'toc',
'list_class' => 'section-nav',
'sublist_class' => '',
'item_class' => 'toc-entry',
- 'item_prefix' => 'toc-'
+ 'item_prefix' => 'toc-',
+ 'nav_to_toc_symbol' => '↥'
}.freeze
def initialize(options)
@@ -25,10 +28,12 @@ def initialize(options)
@ordered_list = options['ordered_list']
@no_toc_class = 'no_toc'
@no_toc_section_class = options['no_toc_section_class']
+ @list_id = options['list_id']
@list_class = options['list_class']
@sublist_class = options['sublist_class']
@item_class = options['item_class']
@item_prefix = options['item_prefix']
+ @nav_to_toc_symbol = options['nav_to_toc_symbol']
end
private
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 0521950..7f24531 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -19,7 +19,7 @@ def toc
end
def build_toc
- %(<#{list_tag} class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}#{list_tag}>)
+ %(<#{list_tag} id="#{@configuration.list_id}" class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}#{list_tag}>)
end
def inject_anchors_into_html
@@ -28,6 +28,14 @@ def inject_anchors_into_html
entry[:header_content].add_previous_sibling(
%()
)
+
+ # Add link 'nav to toc'
+ arr_to_top = [2, 3]
+ next unless arr_to_top.include?(entry[:h_num])
+
+ entry[:header_content].add_next_sibling(
+ %(#{@configuration.nav_to_toc_symbol})
+ )
end
@doc.inner_html
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index 160da4c..61d00b9 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -18,6 +18,6 @@ def test_injects_anchors_into_content
def test_does_not_inject_toc
html = @parser.inject_anchors_into_html
- refute_includes(html, %(
))
+ refute_includes(html, %())
end
end
diff --git a/test/parser/test_invalid_options.rb b/test/parser/test_invalid_options.rb
index db2ad38..104b026 100644
--- a/test/parser/test_invalid_options.rb
+++ b/test/parser/test_invalid_options.rb
@@ -5,7 +5,7 @@
class TestInvalidOptions < Minitest::Test
BASE_HTML = 'h1
'
EXPECTED_HTML = <<~HTML.chomp
-
+
HTML
diff --git a/test/parser/test_ordered_list.rb b/test/parser/test_ordered_list.rb
index c360c87..98af378 100644
--- a/test/parser/test_ordered_list.rb
+++ b/test/parser/test_ordered_list.rb
@@ -27,7 +27,7 @@ def test_basic_ordered_list_top_heading
parse_with_ordered_list
html = @parser.toc
- assert_match(/^/, html)
+ assert_match(/^/, html)
end
def test_ordered_list_sub_headings
@@ -41,7 +41,7 @@ def test_ordered_list_top_heading_with_classes
parse_with_ordered_list_and_classes
html = @parser.toc
- assert_match(/^/, html)
+ assert_match(/^/, html)
end
def test_ordered_list_sub_headings_with_classes
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index a2ddd59..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.rb b/test/parser/test_toc_only_filter.rb
index 2623a85..5a72f49 100644
--- a/test/parser/test_toc_only_filter.rb
+++ b/test/parser/test_toc_only_filter.rb
@@ -12,7 +12,7 @@ def setup
def test_injects_toc_container
html = @parser.build_toc
- assert_includes(html, %())
+ assert_includes(html, %())
end
def test_does_not_return_content
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 26e4ccf..b28d29c 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -12,7 +12,7 @@ class TestVariousTocHtml < Minitest::Test
def test_nested_toc
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML)
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -31,7 +31,7 @@ def test_nested_toc
def test_nested_toc_with_min_and_max
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML, 'min_level' => 2, 'max_level' => 5)
expected = <<~HTML.chomp
-
+
HTML
@@ -47,7 +47,7 @@ def test_complex_nested_toc
h6
HTML
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -74,7 +74,7 @@ def test_decremental_headings1
h1
HTML
expected = <<~HTML.chomp
-
+
- h6
- h5
- h4
@@ -96,7 +96,7 @@ def test_decremental_headings2
h5
HTML
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -129,7 +129,7 @@ def test_no_toc
no_toc h4
HTML
expected = <<~HTML.chomp
-
+
- h1
- h2
@@ -156,7 +156,7 @@ def test_japanese_toc
う
HTML
expected = <<~HTML.chomp
-
+
- あ
- い
@@ -184,7 +184,7 @@ def test_angle_bracket
& < >
HTML
expected = <<~HTML.chomp
-
+
- h1
- <base href>
- & < >
@@ -200,7 +200,7 @@ def test_tags_inside_heading
h2
HTML
expected = <<~HTML.chomp
-
+
@@ -219,7 +219,7 @@ def test_nested_toc_with_no_toc_section_class
h6
HTML
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -254,7 +254,7 @@ def test_nested_toc_with_no_toc_section_class_option
h6
HTML
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -291,7 +291,7 @@ def test_multiple_no_toc_section_classes
h6
HTML
expected = <<~HTML.chomp
-
+
- h1
- h3
@@ -321,7 +321,7 @@ def test_toc_with_explicit_id
h3
HTML
expected = <<~HTML.chomp
-
+
- h1
- h2
- h3
@@ -342,7 +342,7 @@ def test_anchor_is_uniq
h1
HTML
expected = <<~HTML.chomp
-
+
- h1
- h1
- h1
@@ -358,7 +358,7 @@ def test_custom_css_classes
'item_class' => 'custom-item', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
)
expected = <<~HTML.chomp
-
+
- h1
- h3
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index e73d015..a3e77c9 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -9,6 +9,7 @@ def test_default_configuration
assert_equal(1..6, configuration.toc_levels)
refute(configuration.ordered_list)
assert_equal('no_toc_section', configuration.no_toc_section_class)
+ assert_equal('toc', configuration.list_id)
assert_equal('section-nav', configuration.list_class)
assert_equal('', configuration.sublist_class)
assert_equal('toc-entry', configuration.item_class)
@@ -21,6 +22,7 @@ def test_type_error
assert_equal(1..6, configuration.toc_levels)
refute(configuration.ordered_list)
assert_equal('no_toc_section', configuration.no_toc_section_class)
+ assert_equal('toc', configuration.list_id)
assert_equal('section-nav', configuration.list_class)
assert_equal('', configuration.sublist_class)
assert_equal('toc-entry', configuration.item_class)
diff --git a/test/test_jekyll-toc.rb b/test/test_jekyll-toc.rb
index 34fed46..cfdf9c2 100644
--- a/test/test_jekyll-toc.rb
+++ b/test/test_jekyll-toc.rb
@@ -24,7 +24,7 @@ def test_toc
def test_toc_only2
@context = enable_toc_context
- assert_equal "", toc_only(DUMMY_HTML)
+ assert_equal "", toc_only(DUMMY_HTML)
end
def test_inject_anchors2
@@ -34,7 +34,7 @@ def test_inject_anchors2
def test_toc2
@context = enable_toc_context
- assert_equal "#{DUMMY_HTML}", toc(DUMMY_HTML)
+ assert_equal "#{DUMMY_HTML}", toc(DUMMY_HTML)
end
private
diff --git a/test/test_toc_tag.rb b/test/test_toc_tag.rb
index 6749875..fd4c908 100644
--- a/test/test_toc_tag.rb
+++ b/test/test_toc_tag.rb
@@ -17,7 +17,7 @@ def test_toc_tag
site: @stubbed_context1.new({ 'toc' => nil })
)
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
- assert_equal("", tag.render(context))
+ assert_equal("", tag.render(context))
end
def test_toc_tag_returns_empty_string