From aee8fb6e73d2ae91570a47d2799a60cbb067d010 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Mon, 16 Nov 2020 15:23:11 +0100
Subject: [PATCH 1/3] Replace octicon element with a static unicode symbol
---
lib/table_of_contents/parser.rb | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 0521950..7b299ef 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
From c8915dfcf7773770e397cd06fe7e50a7b790da64 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Mon, 16 Nov 2020 16:23:21 +0100
Subject: [PATCH 2/3] Replace the octicon span element with an unicode anchor
symbol
---
lib/table_of_contents/configuration.rb | 6 ++++--
lib/table_of_contents/parser.rb | 2 +-
test/parser/test_inject_anchors_filter.rb | 3 ++-
test/parser/test_toc_filter.rb | 2 +-
test/parser/test_various_toc_html.rb | 6 +++---
5 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb
index aa6a9c4..6a5d9b6 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' => ' 🔗'
}.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 7b299ef..3aab4ac 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -32,7 +32,7 @@ def inject_anchors_into_html
# Add link icon after text
entry[:header_content].add_next_sibling(
- %( 🔗)
+ %(#{@configuration.anchor_symbol})
)
end
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index 160da4c..19a3077 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 🔗<\/a>}, 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
From 11624bfe135a4ebfbfb31eb45b1664846456daad Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Mon, 16 Nov 2020 16:36:12 +0100
Subject: [PATCH 3/3] Fix rubocop
---
.rubocop.yml | 2 ++
lib/table_of_contents/configuration.rb | 2 +-
lib/table_of_contents/parser.rb | 4 ++--
test/parser/test_inject_anchors_filter.rb | 2 +-
4 files changed, 6 insertions(+), 4 deletions(-)
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 6a5d9b6..26e74d2 100644
--- a/lib/table_of_contents/configuration.rb
+++ b/lib/table_of_contents/configuration.rb
@@ -16,7 +16,7 @@ class Configuration
'sublist_class' => '',
'item_class' => 'toc-entry',
'item_prefix' => 'toc-',
- 'anchor_symbol' => ' 🔗'
+ 'anchor_symbol' => ' 🔗' # with leading space
}.freeze
def initialize(options)
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 3aab4ac..b35421e 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -25,11 +25,11 @@ 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(
# %()
# )
-
+
# Add link icon after text
entry[:header_content].add_next_sibling(
%(#{@configuration.anchor_symbol})
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index 19a3077..656e125 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -13,7 +13,7 @@ def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html
# assert_match(%r{Simple H1}, html)
- assert_match(%r{Simple H1 🔗<\/a>}, html)
+ assert_match(%r{Simple H1 🔗}, html)
end
def test_does_not_inject_toc