From 6620373b84127a6962636a638fdb579e9171e495 Mon Sep 17 00:00:00 2001 From: Nicolas Karg <50399433+N7K4@users.noreply.github.com> Date: Mon, 16 Nov 2020 17:06:31 +0100 Subject: [PATCH 1/4] Add rubocop 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 From d1a43871f9874b54cfe2fa0cd90bc5733122297d Mon Sep 17 00:00:00 2001 From: Nicolas Karg <50399433+N7K4@users.noreply.github.com> Date: Mon, 16 Nov 2020 10:34:43 +0100 Subject: [PATCH 2/4] Group the ignore files --- .gitignore | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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 From 363a3d5c0143b9e659fa022c2617316bb398b325 Mon Sep 17 00:00:00 2001 From: Nicolas Karg <50399433+N7K4@users.noreply.github.com> Date: Mon, 16 Nov 2020 17:52:42 +0100 Subject: [PATCH 3/4] Add link to toc --- lib/table_of_contents/configuration.rb | 7 +++++-- lib/table_of_contents/parser.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb index aa6a9c4..bffb266 100644 --- a/lib/table_of_contents/configuration.rb +++ b/lib/table_of_contents/configuration.rb @@ -5,7 +5,8 @@ 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_class, :sublist_class, :item_class, :item_prefix, + :nav_to_toc_symbol DEFAULT_CONFIG = { 'min_level' => 1, @@ -15,7 +16,8 @@ class Configuration 'list_class' => 'section-nav', 'sublist_class' => '', 'item_class' => 'toc-entry', - 'item_prefix' => 'toc-' + 'item_prefix' => 'toc-', + 'nav_to_toc_symbol' => '↥' }.freeze def initialize(options) @@ -29,6 +31,7 @@ def initialize(options) @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..d697738 100644 --- a/lib/table_of_contents/parser.rb +++ b/lib/table_of_contents/parser.rb @@ -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( + %() + ) end @doc.inner_html From 8bf215e8ebec6c5909d36fbe9d5e1f03e11eda4a Mon Sep 17 00:00:00 2001 From: Nicolas Karg <50399433+N7K4@users.noreply.github.com> Date: Mon, 16 Nov 2020 17:07:27 +0100 Subject: [PATCH 4/4] Resolve conflicts in config --- lib/table_of_contents/configuration.rb | 4 ++- lib/table_of_contents/parser.rb | 2 +- test/parser/test_inject_anchors_filter.rb | 2 +- test/parser/test_invalid_options.rb | 2 +- test/parser/test_ordered_list.rb | 4 +-- test/parser/test_toc_filter.rb | 2 +- test/parser/test_toc_only_filter.rb | 2 +- test/parser/test_various_toc_html.rb | 30 +++++++++++------------ test/test_configuration.rb | 2 ++ test/test_jekyll-toc.rb | 4 +-- test/test_toc_tag.rb | 2 +- 11 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb index bffb266..89529f5 100644 --- a/lib/table_of_contents/configuration.rb +++ b/lib/table_of_contents/configuration.rb @@ -5,7 +5,7 @@ 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 = { @@ -13,6 +13,7 @@ class Configuration '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', @@ -27,6 +28,7 @@ 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'] diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb index d697738..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 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, %(