diff --git a/.rubocop.yml b/.rubocop.yml index 3abbf6b..80224ee 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 diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb index aa6a9c4..26e74d2 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_class, :sublist_class, :item_class, :item_prefix, :anchor_symbol DEFAULT_CONFIG = { 'min_level' => 1, @@ -15,7 +15,8 @@ class Configuration 'list_class' => 'section-nav', 'sublist_class' => '', 'item_class' => 'toc-entry', - 'item_prefix' => 'toc-' + 'item_prefix' => 'toc-', + 'anchor_symbol' => ' 🔗' # with leading space }.freeze def initialize(options) @@ -29,6 +30,7 @@ def initialize(options) @sublist_class = options['sublist_class'] @item_class = options['item_class'] @item_prefix = options['item_prefix'] + @anchor_symbol = options['anchor_symbol'] end private diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb index 0521950..b35421e 100644 --- a/lib/table_of_contents/parser.rb +++ b/lib/table_of_contents/parser.rb @@ -25,8 +25,14 @@ def build_toc def inject_anchors_into_html @entries.each do |entry| # NOTE: `entry[:id]` is automatically URL encoded by Nokogiri - entry[:header_content].add_previous_sibling( - %() + + # entry[:header_content].add_previous_sibling( + # %() + # ) + + # Add link icon after text + entry[:header_content].add_next_sibling( + %() ) end diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb index 160da4c..656e125 100644 --- a/test/parser/test_inject_anchors_filter.rb +++ b/test/parser/test_inject_anchors_filter.rb @@ -12,7 +12,8 @@ def setup def test_injects_anchors_into_content html = @parser.inject_anchors_into_html - assert_match(%r{Simple H1}, html) + # assert_match(%r{Simple H1}, html) + assert_match(%r{Simple H1}, html) end def test_does_not_inject_toc diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb index a2ddd59..ecbe686 100644 --- a/test/parser/test_toc_filter.rb +++ b/test/parser/test_toc_filter.rb @@ -12,7 +12,7 @@ def setup def test_injects_anchors html = @parser.toc - assert_match(%r{Simple H1}, html) + assert_match(%r{Simple H1}, html) end def test_nested_toc diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb index 26e4ccf..03022fa 100644 --- a/test/parser/test_various_toc_html.rb +++ b/test/parser/test_various_toc_html.rb @@ -171,9 +171,9 @@ def test_japanese_toc assert_equal(expected, parser.build_toc) html_with_anchors = parser.inject_anchors_into_html - assert_match(%r{あ}, html_with_anchors) - assert_match(%r{い}, html_with_anchors) - assert_match(%r{う}, html_with_anchors) + assert_match(%r{あ}, html_with_anchors) + assert_match(%r{い}, html_with_anchors) + assert_match(%r{う}, html_with_anchors) end # ref. https://github.com/toshimaru/jekyll-toc/issues/45