From b1c34b5fab4401d2538e34c5a5ccb3b2bf9f8500 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 06:13:09 +0200
Subject: [PATCH 01/31] Add configurable list_id for root toc-element
---
lib/table_of_contents/configuration.rb | 84 +++++----
lib/table_of_contents/parser.rb | 252 ++++++++++++-------------
2 files changed, 169 insertions(+), 167 deletions(-)
diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb
index 61eeeeb..1c17b2e 100644
--- a/lib/table_of_contents/configuration.rb
+++ b/lib/table_of_contents/configuration.rb
@@ -1,41 +1,43 @@
-# frozen_string_literal: true
-
-module Jekyll
- module TableOfContents
- # jekyll-toc configuration class
- class Configuration
- attr_accessor :toc_levels, :no_toc_class, :no_toc_section_class,
- :list_class, :sublist_class, :item_class, :item_prefix
-
- DEFAULT_CONFIG = {
- 'min_level' => 1,
- 'max_level' => 6,
- 'no_toc_section_class' => 'no_toc_section',
- 'list_class' => 'section-nav',
- 'sublist_class' => '',
- 'item_class' => 'toc-entry',
- 'item_prefix' => 'toc-'
- }.freeze
-
- def initialize(options)
- options = generate_option_hash(options)
-
- @toc_levels = options['min_level']..options['max_level']
- @no_toc_class = 'no_toc'
- @no_toc_section_class = options['no_toc_section_class']
- @list_class = options['list_class']
- @sublist_class = options['sublist_class']
- @item_class = options['item_class']
- @item_prefix = options['item_prefix']
- end
-
- private
-
- def generate_option_hash(options)
- DEFAULT_CONFIG.merge(options)
- rescue TypeError
- DEFAULT_CONFIG
- end
- end
- end
-end
+# frozen_string_literal: true
+
+module Jekyll
+ module TableOfContents
+ # jekyll-toc configuration class
+ class Configuration
+ attr_accessor :toc_levels, :no_toc_class, :no_toc_section_class,
+ :list_class, :list_id, :sublist_class, :item_class, :item_prefix
+
+ DEFAULT_CONFIG = {
+ 'min_level' => 1,
+ 'max_level' => 6,
+ 'no_toc_section_class' => 'no_toc_section',
+ 'list_class' => 'section-nav',
+ 'list_id' => 'toc',
+ 'sublist_class' => '',
+ 'item_class' => 'toc-entry',
+ 'item_prefix' => 'toc-'
+ }.freeze
+
+ def initialize(options)
+ options = generate_option_hash(options)
+
+ @toc_levels = options['min_level']..options['max_level']
+ @no_toc_class = 'no_toc'
+ @no_toc_section_class = options['no_toc_section_class']
+ @list_class = options['list_class']
+ @list_id = options['list_id']
+ @sublist_class = options['sublist_class']
+ @item_class = options['item_class']
+ @item_prefix = options['item_prefix']
+ end
+
+ private
+
+ def generate_option_hash(options)
+ DEFAULT_CONFIG.merge(options)
+ rescue TypeError
+ DEFAULT_CONFIG
+ end
+ end
+ end
+end
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 036251d..cc5e2fe 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -1,126 +1,126 @@
-# frozen_string_literal: true
-
-module Jekyll
- module TableOfContents
- # Parse html contents and generate table of contents
- class Parser
- PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
-
- def initialize(html, options = {})
- @doc = Nokogiri::HTML::DocumentFragment.parse(html)
- @configuration = Configuration.new(options)
- @entries = parse_content
- end
-
- def toc
- build_toc + inject_anchors_into_html
- end
-
- def build_toc
- %(
\n#{build_toc_list(@entries)}
)
- end
-
- def inject_anchors_into_html
- @entries.each do |entry|
- entry[:header_content].add_previous_sibling(
- %()
- )
- end
-
- @doc.inner_html
- end
-
- private
-
- # parse logic is from html-pipeline toc_filter
- # https://github.com/jch/html-pipeline/blob/v1.1.0/lib/html/pipeline/toc_filter.rb
- def parse_content
- headers = Hash.new(0)
-
- (@doc.css(toc_headings) - @doc.css(toc_headings_in_no_toc_section))
- .reject { |n| n.classes.include?(@configuration.no_toc_class) }
- .inject([]) do |entries, node|
- text = node.text
- id = node.attribute('id') || text
- .downcase
- .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
- .tr(' ', '-') # replace spaces with dash
-
- suffix_num = headers[id]
- headers[id] += 1
-
- entries << {
- id: suffix_num.zero? ? id : "#{id}-#{suffix_num}",
- text: CGI.escapeHTML(text),
- node_name: node.name,
- header_content: node.children.first,
- h_num: node.name.delete('h').to_i
- }
- end
- end
-
- # Returns the list items for entries
- def build_toc_list(entries)
- i = 0
- toc_list = +''
- min_h_num = entries.map { |e| e[:h_num] }.min
-
- while i < entries.count
- entry = entries[i]
- if entry[:h_num] == min_h_num
- # If the current entry should not be indented in the list, add the entry to the list
- toc_list << %(#{entry[:text]})
- # If the next entry should be indented in the list, generate a sublist
- next_i = i + 1
- if next_i < entries.count && entries[next_i][:h_num] > min_h_num
- nest_entries = get_nest_entries(entries[next_i, entries.count], min_h_num)
- toc_list << %(\n\n#{build_toc_list(nest_entries)}
\n)
- i += nest_entries.count
- end
- # Add the closing tag for the current entry in the list
- toc_list << %(\n)
- elsif entry[:h_num] > min_h_num
- # If the current entry should be indented in the list, generate a sublist
- nest_entries = get_nest_entries(entries[i, entries.count], min_h_num)
- toc_list << build_toc_list(nest_entries)
- i += nest_entries.count - 1
- end
- i += 1
- end
-
- toc_list
- end
-
- # Returns the entries in a nested list
- # The nested list starts at the first entry in entries (inclusive)
- # The nested list ends at the first entry in entries with depth min_h_num or greater (exclusive)
- def get_nest_entries(entries, min_h_num)
- entries.inject([]) do |nest_entries, entry|
- break nest_entries if entry[:h_num] == min_h_num
-
- nest_entries << entry
- end
- end
-
- def toc_headings
- @configuration.toc_levels.map { |level| "h#{level}" }.join(',')
- end
-
- def toc_headings_in_no_toc_section
- if @configuration.no_toc_section_class.is_a? Array
- @configuration.no_toc_section_class.map { |cls| toc_headings_within(cls) }.join(',')
- else
- toc_headings_within(@configuration.no_toc_section_class)
- end
- end
-
- def toc_headings_within(class_name)
- @configuration.toc_levels.map { |level| ".#{class_name} h#{level}" }.join(',')
- end
-
- def ul_attributes
- @ul_attributes ||= @configuration.sublist_class.empty? ? '' : %( class="#{@configuration.sublist_class}")
- end
- end
- end
-end
+# frozen_string_literal: true
+
+module Jekyll
+ module TableOfContents
+ # Parse html contents and generate table of contents
+ class Parser
+ PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
+
+ def initialize(html, options = {})
+ @doc = Nokogiri::HTML::DocumentFragment.parse(html)
+ @configuration = Configuration.new(options)
+ @entries = parse_content
+ end
+
+ def toc
+ build_toc + inject_anchors_into_html
+ end
+
+ def build_toc
+ %(\n#{build_toc_list(@entries)}
)
+ end
+
+ def inject_anchors_into_html
+ @entries.each do |entry|
+ entry[:header_content].add_previous_sibling(
+ %()
+ )
+ end
+
+ @doc.inner_html
+ end
+
+ private
+
+ # parse logic is from html-pipeline toc_filter
+ # https://github.com/jch/html-pipeline/blob/v1.1.0/lib/html/pipeline/toc_filter.rb
+ def parse_content
+ headers = Hash.new(0)
+
+ (@doc.css(toc_headings) - @doc.css(toc_headings_in_no_toc_section))
+ .reject { |n| n.classes.include?(@configuration.no_toc_class) }
+ .inject([]) do |entries, node|
+ text = node.text
+ id = node.attribute('id') || text
+ .downcase
+ .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
+ .tr(' ', '-') # replace spaces with dash
+
+ suffix_num = headers[id]
+ headers[id] += 1
+
+ entries << {
+ id: suffix_num.zero? ? id : "#{id}-#{suffix_num}",
+ text: CGI.escapeHTML(text),
+ node_name: node.name,
+ header_content: node.children.first,
+ h_num: node.name.delete('h').to_i
+ }
+ end
+ end
+
+ # Returns the list items for entries
+ def build_toc_list(entries)
+ i = 0
+ toc_list = +''
+ min_h_num = entries.map { |e| e[:h_num] }.min
+
+ while i < entries.count
+ entry = entries[i]
+ if entry[:h_num] == min_h_num
+ # If the current entry should not be indented in the list, add the entry to the list
+ toc_list << %(#{entry[:text]})
+ # If the next entry should be indented in the list, generate a sublist
+ next_i = i + 1
+ if next_i < entries.count && entries[next_i][:h_num] > min_h_num
+ nest_entries = get_nest_entries(entries[next_i, entries.count], min_h_num)
+ toc_list << %(\n\n#{build_toc_list(nest_entries)}
\n)
+ i += nest_entries.count
+ end
+ # Add the closing tag for the current entry in the list
+ toc_list << %(\n)
+ elsif entry[:h_num] > min_h_num
+ # If the current entry should be indented in the list, generate a sublist
+ nest_entries = get_nest_entries(entries[i, entries.count], min_h_num)
+ toc_list << build_toc_list(nest_entries)
+ i += nest_entries.count - 1
+ end
+ i += 1
+ end
+
+ toc_list
+ end
+
+ # Returns the entries in a nested list
+ # The nested list starts at the first entry in entries (inclusive)
+ # The nested list ends at the first entry in entries with depth min_h_num or greater (exclusive)
+ def get_nest_entries(entries, min_h_num)
+ entries.inject([]) do |nest_entries, entry|
+ break nest_entries if entry[:h_num] == min_h_num
+
+ nest_entries << entry
+ end
+ end
+
+ def toc_headings
+ @configuration.toc_levels.map { |level| "h#{level}" }.join(',')
+ end
+
+ def toc_headings_in_no_toc_section
+ if @configuration.no_toc_section_class.is_a? Array
+ @configuration.no_toc_section_class.map { |cls| toc_headings_within(cls) }.join(',')
+ else
+ toc_headings_within(@configuration.no_toc_section_class)
+ end
+ end
+
+ def toc_headings_within(class_name)
+ @configuration.toc_levels.map { |level| ".#{class_name} h#{level}" }.join(',')
+ end
+
+ def ul_attributes
+ @ul_attributes ||= @configuration.sublist_class.empty? ? '' : %( class="#{@configuration.sublist_class}")
+ end
+ end
+ end
+end
From 9036248a2671fa1b391a00ffec83403ca5e712dd Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 06:21:57 +0200
Subject: [PATCH 02/31] Fix unit tests (add id="toc")
---
test/parser/test_inject_anchors_filter.rb | 46 +-
test/parser/test_option_error.rb | 80 +-
test/parser/test_toc_filter.rb | 72 +-
test/parser/test_toc_only_filter.rb | 46 +-
test/parser/test_various_toc_html.rb | 886 +++++++++++-----------
test/test_configuration.rb | 56 +-
test/test_jekyll-toc.rb | 104 +--
test/test_toc_tag.rb | 56 +-
8 files changed, 674 insertions(+), 672 deletions(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index c9158e5..d2f76b0 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -1,23 +1,23 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestInjectAnchorsFilter < Minitest::Test
- include TestHelpers
-
- def setup
- read_html_and_create_parser
- end
-
- def test_injects_anchors_into_content
- html = @parser.inject_anchors_into_html
-
- assert_match(%r{Simple H1}, html)
- end
-
- def test_does_not_inject_toc
- html = @parser.inject_anchors_into_html
-
- assert_nil(// =~ html)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestInjectAnchorsFilter < Minitest::Test
+ include TestHelpers
+
+ def setup
+ read_html_and_create_parser
+ end
+
+ def test_injects_anchors_into_content
+ html = @parser.inject_anchors_into_html
+
+ assert_match(%r{Simple H1}, html)
+ end
+
+ def test_does_not_inject_toc
+ html = @parser.inject_anchors_into_html
+
+ assert_nil(// =~ html)
+ end
+end
diff --git a/test/parser/test_option_error.rb b/test/parser/test_option_error.rb
index c469e29..8f85b0b 100644
--- a/test/parser/test_option_error.rb
+++ b/test/parser/test_option_error.rb
@@ -1,40 +1,40 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestOptionError < Minitest::Test
- BASE_HTML = 'h1
'
- EXPECTED_HTML = <<~HTML
-
- HTML
-
- def test_option_is_nil
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, nil)
- doc = Nokogiri::HTML(parser.toc)
- expected = EXPECTED_HTML
- assert_equal(expected, doc.css('ul.section-nav').to_s)
- end
-
- def test_option_is_epmty_string
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, '')
- doc = Nokogiri::HTML(parser.toc)
- expected = EXPECTED_HTML
- assert_equal(expected, doc.css('ul.section-nav').to_s)
- end
-
- def test_option_is_string
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, 'string')
- doc = Nokogiri::HTML(parser.toc)
- expected = EXPECTED_HTML
- assert_equal(expected, doc.css('ul.section-nav').to_s)
- end
-
- def test_option_is_array
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, [])
- doc = Nokogiri::HTML(parser.toc)
- expected = EXPECTED_HTML
- assert_equal(expected, doc.css('ul.section-nav').to_s)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestOptionError < Minitest::Test
+ BASE_HTML = 'h1
'
+ EXPECTED_HTML = <<~HTML
+
+ HTML
+
+ def test_option_is_nil
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, nil)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = EXPECTED_HTML
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
+ end
+
+ def test_option_is_epmty_string
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, '')
+ doc = Nokogiri::HTML(parser.toc)
+ expected = EXPECTED_HTML
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
+ end
+
+ def test_option_is_string
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, 'string')
+ doc = Nokogiri::HTML(parser.toc)
+ expected = EXPECTED_HTML
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
+ end
+
+ def test_option_is_array
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, [])
+ doc = Nokogiri::HTML(parser.toc)
+ expected = EXPECTED_HTML
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
+ end
+end
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index a2ddd59..da9edb7 100644
--- a/test/parser/test_toc_filter.rb
+++ b/test/parser/test_toc_filter.rb
@@ -1,36 +1,36 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestTOCFilter < Minitest::Test
- include TestHelpers
-
- def setup
- read_html_and_create_parser
- end
-
- def test_injects_anchors
- html = @parser.toc
-
- assert_match(%r{Simple H1}, html)
- end
-
- def test_nested_toc
- doc = Nokogiri::HTML(@parser.toc)
- nested_h6_text = doc.css('ul.section-nav')
- .css('li.toc-h1')
- .css('li.toc-h2')
- .css('li.toc-h3')
- .css('li.toc-h4')
- .css('li.toc-h5')
- .css('li.toc-h6')
- .text
- assert_equal('Simple H6', nested_h6_text)
- end
-
- def test_injects_toc_container
- html = @parser.toc
-
- assert_match(//, html)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestTOCFilter < Minitest::Test
+ include TestHelpers
+
+ def setup
+ read_html_and_create_parser
+ end
+
+ def test_injects_anchors
+ html = @parser.toc
+
+ assert_match(%r{Simple H1}, html)
+ end
+
+ def test_nested_toc
+ doc = Nokogiri::HTML(@parser.toc)
+ nested_h6_text = doc.css('ul.section-nav')
+ .css('li.toc-h1')
+ .css('li.toc-h2')
+ .css('li.toc-h3')
+ .css('li.toc-h4')
+ .css('li.toc-h5')
+ .css('li.toc-h6')
+ .text
+ assert_equal('Simple H6', nested_h6_text)
+ end
+
+ def test_injects_toc_container
+ html = @parser.toc
+
+ assert_match(//, html)
+ end
+end
diff --git a/test/parser/test_toc_only_filter.rb b/test/parser/test_toc_only_filter.rb
index cc0b9eb..76d7a4d 100644
--- a/test/parser/test_toc_only_filter.rb
+++ b/test/parser/test_toc_only_filter.rb
@@ -1,23 +1,23 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestTOCOnlyFilter < Minitest::Test
- include TestHelpers
-
- def setup
- read_html_and_create_parser
- end
-
- def test_injects_toc_container
- html = @parser.build_toc
-
- assert_match(//, html)
- end
-
- def test_does_not_return_content
- html = @parser.build_toc
-
- assert_nil(%r{Simple H1
} =~ html)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestTOCOnlyFilter < Minitest::Test
+ include TestHelpers
+
+ def setup
+ read_html_and_create_parser
+ end
+
+ def test_injects_toc_container
+ html = @parser.build_toc
+
+ assert_match(//, html)
+ end
+
+ def test_does_not_return_content
+ html = @parser.build_toc
+
+ assert_nil(%r{Simple H1
} =~ html)
+ end
+end
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 2668b31..4c619fe 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -1,443 +1,443 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestVariousTocHtml < Minitest::Test
- # ref. https://github.com/toshimaru/jekyll-toc/issues/45
- ANGLE_BRACKET_HTML = <<~HTML
- h1
- <base href>
- & < >
- HTML
-
- NO_TOC_HTML = <<~HTML
- h1
- no_toc h1
- h2
- no_toc h2
- h3
- no_toc h3
- h4
- no_toc h4
- HTML
-
- JAPANESE_HEADINGS_HTML = <<~HTML
- あ
- い
- う
- HTML
-
- TAGS_INSIDE_HEADINGS_HTML = <<~HTML
- h2
- h2
- HTML
-
- TEST_HTML_1 = <<~HTML
- h1
- h3
- h6
- HTML
-
- TEST_HTML_2 = <<~HTML
- h1
- h3
- h2
- h6
- HTML
-
- TEST_HTML_3 = <<~HTML
- h6
- h5
- h4
- h3
- h2
- h1
- HTML
-
- TEST_HTML_4 = <<~HTML
- h1
- h3
- h2
- h4
- h5
- HTML
-
- def test_nested_toc
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_nested_toc_with_min_and_max
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1, 'min_level' => 2, 'max_level' => 5)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_complex_nested_toc
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_2)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_decremental_headings1
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_3)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_decremental_headings2
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_4)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
-
- assert_equal(expected, doc.css('ul.section-nav').to_s)
- end
-
- def test_no_toc
- parser = Jekyll::TableOfContents::Parser.new(NO_TOC_HTML)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_japanese_toc
- parser = Jekyll::TableOfContents::Parser.new(JAPANESE_HEADINGS_HTML)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_angle_bracket
- parser = Jekyll::TableOfContents::Parser.new(ANGLE_BRACKET_HTML)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- def test_tags_inside_heading
- parser = Jekyll::TableOfContents::Parser.new(TAGS_INSIDE_HEADINGS_HTML)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
-
- assert_equal(expected, actual)
- end
-
- TEST_HTML_IGNORE = <<~HTML
- h1
-
-
h2
-
- h3
- h6
- HTML
-
- def test_nested_toc_with_no_toc_section_class
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
- assert_equal(expected, actual)
-
- html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_includes(html, 'h2
')
- end
-
- TEST_HTML_IGNORE_2 = <<~HTML
- h1
-
-
h2
-
- h3
-
-
h4
- h5
-
- h6
- HTML
-
- def test_nested_toc_with_no_toc_section_class_option
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE_2, 'no_toc_section_class' => 'exclude')
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
- assert_equal(expected, actual)
-
- html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_includes(html, 'h2
')
- assert_includes(html, 'h4
')
- assert_includes(html, 'h5
')
- end
-
- TEST_HTML_IGNORE_3 = <<~HTML
- h1
-
-
h2
-
- h3
-
-
h4
- h5
-
- h6
- HTML
-
- def test_multiple_no_toc_section_classes
- parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE_3, 'no_toc_section_class' => ['no_toc_section', 'exclude'])
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
- assert_equal(expected, actual)
-
- html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_includes(html, 'h2
')
- assert_includes(html, 'h4
')
- assert_includes(html, 'h5
')
- end
-
- TEST_EXPLICIT_ID = <<~HTML
- h1
- h2
- h3
- HTML
-
- def test_toc_with_explicit_id
- parser = Jekyll::TableOfContents::Parser.new(TEST_EXPLICIT_ID)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
- assert_equal(expected, actual)
-
- html = parser.inject_anchors_into_html
- assert_includes(html, %())
- assert_includes(html, %())
- assert_includes(html, %())
- end
-
- TEST_UNIQ_ID = <<~HTML
- h1
- h1
- h1
- HTML
-
- def test_anchor_is_uniq
- parser = Jekyll::TableOfContents::Parser.new(TEST_UNIQ_ID)
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
- actual = doc.css('ul.section-nav').to_s
- assert_equal(expected, actual)
- end
-
- def test_custom_css_classes
- parser = Jekyll::TableOfContents::Parser.new(
- TEST_HTML_1,
- 'item_class' => 'custom-item', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
- )
- doc = Nokogiri::HTML(parser.toc)
- expected = <<~HTML
-
- HTML
-
- assert_equal(expected, doc.css('ul.custom-list').to_s)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestVariousTocHtml < Minitest::Test
+ # ref. https://github.com/toshimaru/jekyll-toc/issues/45
+ ANGLE_BRACKET_HTML = <<~HTML
+ h1
+ <base href>
+ & < >
+ HTML
+
+ NO_TOC_HTML = <<~HTML
+ h1
+ no_toc h1
+ h2
+ no_toc h2
+ h3
+ no_toc h3
+ h4
+ no_toc h4
+ HTML
+
+ JAPANESE_HEADINGS_HTML = <<~HTML
+ あ
+ い
+ う
+ HTML
+
+ TAGS_INSIDE_HEADINGS_HTML = <<~HTML
+ h2
+ h2
+ HTML
+
+ TEST_HTML_1 = <<~HTML
+ h1
+ h3
+ h6
+ HTML
+
+ TEST_HTML_2 = <<~HTML
+ h1
+ h3
+ h2
+ h6
+ HTML
+
+ TEST_HTML_3 = <<~HTML
+ h6
+ h5
+ h4
+ h3
+ h2
+ h1
+ HTML
+
+ TEST_HTML_4 = <<~HTML
+ h1
+ h3
+ h2
+ h4
+ h5
+ HTML
+
+ def test_nested_toc
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_nested_toc_with_min_and_max
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1, 'min_level' => 2, 'max_level' => 5)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_complex_nested_toc
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_2)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_decremental_headings1
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_3)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_decremental_headings2
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_4)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
+ end
+
+ def test_no_toc
+ parser = Jekyll::TableOfContents::Parser.new(NO_TOC_HTML)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_japanese_toc
+ parser = Jekyll::TableOfContents::Parser.new(JAPANESE_HEADINGS_HTML)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_angle_bracket
+ parser = Jekyll::TableOfContents::Parser.new(ANGLE_BRACKET_HTML)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ def test_tags_inside_heading
+ parser = Jekyll::TableOfContents::Parser.new(TAGS_INSIDE_HEADINGS_HTML)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
+
+ TEST_HTML_IGNORE = <<~HTML
+ h1
+
+
h2
+
+ h3
+ h6
+ HTML
+
+ def test_nested_toc_with_no_toc_section_class
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+ assert_equal(expected, actual)
+
+ html = parser.inject_anchors_into_html
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_includes(html, 'h2
')
+ end
+
+ TEST_HTML_IGNORE_2 = <<~HTML
+ h1
+
+
h2
+
+ h3
+
+
h4
+ h5
+
+ h6
+ HTML
+
+ def test_nested_toc_with_no_toc_section_class_option
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE_2, 'no_toc_section_class' => 'exclude')
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+ assert_equal(expected, actual)
+
+ html = parser.inject_anchors_into_html
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_includes(html, 'h2
')
+ assert_includes(html, 'h4
')
+ assert_includes(html, 'h5
')
+ end
+
+ TEST_HTML_IGNORE_3 = <<~HTML
+ h1
+
+
h2
+
+ h3
+
+
h4
+ h5
+
+ h6
+ HTML
+
+ def test_multiple_no_toc_section_classes
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_IGNORE_3, 'no_toc_section_class' => ['no_toc_section', 'exclude'])
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+ assert_equal(expected, actual)
+
+ html = parser.inject_anchors_into_html
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_includes(html, 'h2
')
+ assert_includes(html, 'h4
')
+ assert_includes(html, 'h5
')
+ end
+
+ TEST_EXPLICIT_ID = <<~HTML
+ h1
+ h2
+ h3
+ HTML
+
+ def test_toc_with_explicit_id
+ parser = Jekyll::TableOfContents::Parser.new(TEST_EXPLICIT_ID)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+ assert_equal(expected, actual)
+
+ html = parser.inject_anchors_into_html
+ assert_includes(html, %())
+ assert_includes(html, %())
+ assert_includes(html, %())
+ end
+
+ TEST_UNIQ_ID = <<~HTML
+ h1
+ h1
+ h1
+ HTML
+
+ def test_anchor_is_uniq
+ parser = Jekyll::TableOfContents::Parser.new(TEST_UNIQ_ID)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+ assert_equal(expected, actual)
+ end
+
+ def test_custom_css_classes
+ parser = Jekyll::TableOfContents::Parser.new(
+ TEST_HTML_1,
+ 'item_class' => 'custom-item', 'list_class' => 'custom-list', 'sublist_class' => 'custom-sublist', 'item_prefix' => 'custom-prefix-'
+ )
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<~HTML
+
+ HTML
+
+ assert_equal(expected, doc.css('ul.custom-list').to_s)
+ end
+end
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index caf16f0..4a0e914 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -1,27 +1,29 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestConfiguration < Minitest::Test
- def test_default_conf1guration
- configuration = Jekyll::TableOfContents::Configuration.new({})
-
- assert_equal configuration.toc_levels, 1..6
- assert_equal configuration.no_toc_section_class, 'no_toc_section'
- assert_equal configuration.list_class, 'section-nav'
- assert_equal configuration.sublist_class, ''
- assert_equal configuration.item_class, 'toc-entry'
- assert_equal configuration.item_prefix, 'toc-'
- end
-
- def test_type_error
- configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
-
- assert_equal configuration.toc_levels, 1..6
- assert_equal configuration.no_toc_section_class, 'no_toc_section'
- assert_equal configuration.list_class, 'section-nav'
- assert_equal configuration.sublist_class, ''
- assert_equal configuration.item_class, 'toc-entry'
- assert_equal configuration.item_prefix, 'toc-'
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestConfiguration < Minitest::Test
+ def test_default_conf1guration
+ configuration = Jekyll::TableOfContents::Configuration.new({})
+
+ assert_equal configuration.toc_levels, 1..6
+ assert_equal configuration.no_toc_section_class, 'no_toc_section'
+ assert_equal configuration.list_class, 'section-nav'
+ assert_equal configuration.list_id, 'toc'
+ assert_equal configuration.sublist_class, ''
+ assert_equal configuration.item_class, 'toc-entry'
+ assert_equal configuration.item_prefix, 'toc-'
+ end
+
+ def test_type_error
+ configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
+
+ assert_equal configuration.toc_levels, 1..6
+ assert_equal configuration.no_toc_section_class, 'no_toc_section'
+ assert_equal configuration.list_class, 'section-nav'
+ assert_equal configuration.list_id, 'toc'
+ assert_equal configuration.sublist_class, ''
+ assert_equal configuration.item_class, 'toc-entry'
+ assert_equal configuration.item_prefix, 'toc-'
+ end
+end
diff --git a/test/test_jekyll-toc.rb b/test/test_jekyll-toc.rb
index 34fed46..634dd47 100644
--- a/test/test_jekyll-toc.rb
+++ b/test/test_jekyll-toc.rb
@@ -1,52 +1,52 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestTableOfContentsFilter < Minitest::Test
- include Jekyll::TableOfContentsFilter
-
- DUMMY_HTML = 'Dummy HTML Content
'
-
- def test_toc_only
- @context = disable_toc_context
- assert_empty toc_only(DUMMY_HTML)
- end
-
- def test_inject_anchors
- @context = disable_toc_context
- assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
- end
-
- def test_toc
- @context = disable_toc_context
- assert_equal DUMMY_HTML, toc(DUMMY_HTML)
- end
-
- def test_toc_only2
- @context = enable_toc_context
- assert_equal "", toc_only(DUMMY_HTML)
- end
-
- def test_inject_anchors2
- @context = enable_toc_context
- assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
- end
-
- def test_toc2
- @context = enable_toc_context
- assert_equal "#{DUMMY_HTML}", toc(DUMMY_HTML)
- end
-
- private
-
- def disable_toc_context
- Struct.new(:registers).new(page: { 'toc' => false })
- end
-
- def enable_toc_context
- Struct.new(:registers).new(
- page: { 'toc' => true },
- site: Struct.new(:config).new({ 'toc' => false })
- )
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestTableOfContentsFilter < Minitest::Test
+ include Jekyll::TableOfContentsFilter
+
+ DUMMY_HTML = 'Dummy HTML Content
'
+
+ def test_toc_only
+ @context = disable_toc_context
+ assert_empty toc_only(DUMMY_HTML)
+ end
+
+ def test_inject_anchors
+ @context = disable_toc_context
+ assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
+ end
+
+ def test_toc
+ @context = disable_toc_context
+ assert_equal DUMMY_HTML, toc(DUMMY_HTML)
+ end
+
+ def test_toc_only2
+ @context = enable_toc_context
+ assert_equal "", toc_only(DUMMY_HTML)
+ end
+
+ def test_inject_anchors2
+ @context = enable_toc_context
+ assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
+ end
+
+ def test_toc2
+ @context = enable_toc_context
+ assert_equal "#{DUMMY_HTML}", toc(DUMMY_HTML)
+ end
+
+ private
+
+ def disable_toc_context
+ Struct.new(:registers).new(page: { 'toc' => false })
+ end
+
+ def enable_toc_context
+ Struct.new(:registers).new(
+ page: { 'toc' => true },
+ site: Struct.new(:config).new({ 'toc' => false })
+ )
+ end
+end
diff --git a/test/test_toc_tag.rb b/test/test_toc_tag.rb
index ce2b30e..b7f48de 100644
--- a/test/test_toc_tag.rb
+++ b/test/test_toc_tag.rb
@@ -1,28 +1,28 @@
-# frozen_string_literal: true
-
-require 'test_helper'
-
-class TestTableOfContentsTag < Minitest::Test
- include Liquid
-
- def setup
- @stubbed_context = Struct.new(:registers)
- @stubbed_context1 = Struct.new(:config)
- @stubbed_context2 = Struct.new(:toc, :content)
- end
-
- def test_toc_tag
- context = @stubbed_context.new(
- page: @stubbed_context2.new({ 'toc' => false }, 'test
'),
- site: @stubbed_context1.new({ 'toc' => nil })
- )
- tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
- assert_equal tag.render(context), ""
- end
-
- def test_toc_tag_returns_empty_string
- context = @stubbed_context.new(page: { 'toc' => false })
- tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
- assert_empty tag.render(context)
- end
-end
+# frozen_string_literal: true
+
+require 'test_helper'
+
+class TestTableOfContentsTag < Minitest::Test
+ include Liquid
+
+ def setup
+ @stubbed_context = Struct.new(:registers)
+ @stubbed_context1 = Struct.new(:config)
+ @stubbed_context2 = Struct.new(:toc, :content)
+ end
+
+ def test_toc_tag
+ context = @stubbed_context.new(
+ page: @stubbed_context2.new({ 'toc' => false }, 'test
'),
+ site: @stubbed_context1.new({ 'toc' => nil })
+ )
+ tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
+ assert_equal tag.render(context), ""
+ end
+
+ def test_toc_tag_returns_empty_string
+ context = @stubbed_context.new(page: { 'toc' => false })
+ tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
+ assert_empty tag.render(context)
+ end
+end
From 694e87f5c2a0c0e35cdfd87a50e4efbf494d1794 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 08:07:46 +0200
Subject: [PATCH 03/31] Add config key inject_anchors_content to set the cntent
of the anchor
---
README.md | 24 ++++++++++++++++++++----
lib/table_of_contents/configuration.rb | 7 +++++--
lib/table_of_contents/parser.rb | 2 +-
test/test_configuration.rb | 2 ++
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index e85fc30..50651bd 100644
--- a/README.md
+++ b/README.md
@@ -100,8 +100,9 @@ above the content but at some other place of the page, i.e. an aside.
#### `inject_anchors` filter
-Injects HTML anchors into the content without actually outputting the TOC itself.
-They are of the form:
+Injects HTML anchors into the content without actually outputting the TOC itself.
+
+They are of the form (usage of [octicons](https://github.com/primer/octicons) as icon collection):
```html
@@ -109,8 +110,23 @@ They are of the form:
```
-This is only useful when the TOC itself should be placed at some other
-location with the `toc_only` filter.
+They are of the form (unicode symbol):
+
+```html
+
+ 🔗
+
+```
+
+This is useful when the TOC itself should be placed at some other location with the `toc_only` filter.
+
+The second usecase is when you want to **share a link** to the page and link directly to the headline / section.
+
+There is a new configuration `inject_anchors_content` key, possible values are (or what you prefer)
+
+* `🔗 ` (default) to add a unicode symbol (chain) for an link
+* `` to use the octicon icon
+* ` ` an empty string or a space is for **hide** the anchor
## Generated HTML
diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb
index 61eeeeb..6408891 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_accessor :toc_levels, :no_toc_class, :no_toc_section_class,
- :list_class, :sublist_class, :item_class, :item_prefix
+ :list_class, :sublist_class, :item_class, :item_prefix,
+ :inject_anchors_content
DEFAULT_CONFIG = {
'min_level' => 1,
@@ -14,7 +15,8 @@ class Configuration
'list_class' => 'section-nav',
'sublist_class' => '',
'item_class' => 'toc-entry',
- 'item_prefix' => 'toc-'
+ 'item_prefix' => 'toc-',
+ 'inject_anchors_content' => '🔗 '
}.freeze
def initialize(options)
@@ -27,6 +29,7 @@ def initialize(options)
@sublist_class = options['sublist_class']
@item_class = options['item_class']
@item_prefix = options['item_prefix']
+ @inject_anchors_content = options['inject_anchors_content']
end
private
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 036251d..8fe66bd 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -23,7 +23,7 @@ def build_toc
def inject_anchors_into_html
@entries.each do |entry|
entry[:header_content].add_previous_sibling(
- %()
+ %(#{@configuration.inject_anchors_content})
)
end
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index caf16f0..a49619a 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -12,6 +12,7 @@ def test_default_conf1guration
assert_equal configuration.sublist_class, ''
assert_equal configuration.item_class, 'toc-entry'
assert_equal configuration.item_prefix, 'toc-'
+ assert_equal configuration.inject_anchors_content, '🔗 '
end
def test_type_error
@@ -23,5 +24,6 @@ def test_type_error
assert_equal configuration.sublist_class, ''
assert_equal configuration.item_class, 'toc-entry'
assert_equal configuration.item_prefix, 'toc-'
+ assert_equal configuration.inject_anchors_content, '🔗 '
end
end
From aeea2ba97d2d2db17b7865b99e68859738dd4319 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:08:33 +0200
Subject: [PATCH 04/31] Add id to h-elements
---
lib/table_of_contents/parser.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 036251d..a621bfa 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -22,6 +22,9 @@ def build_toc
def inject_anchors_into_html
@entries.each do |entry|
+ # Add id to h-element
+ entry[:header_parent].set_attribute('id', "#{entry[:id]}")
+
entry[:header_content].add_previous_sibling(
%()
)
@@ -53,6 +56,7 @@ def parse_content
id: suffix_num.zero? ? id : "#{id}-#{suffix_num}",
text: CGI.escapeHTML(text),
node_name: node.name,
+ header_parent: node,
header_content: node.children.first,
h_num: node.name.delete('h').to_i
}
From 287391fe25206cb4d4f290ddc284045a042f89b3 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:22:44 +0200
Subject: [PATCH 05/31] Delete coverage.yml
---
.github/workflows/coverage.yml | 22 ----------------------
1 file changed, 22 deletions(-)
delete mode 100644 .github/workflows/coverage.yml
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
deleted file mode 100644
index 4d676d7..0000000
--- a/.github/workflows/coverage.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-name: Coverage
-on: [push]
-jobs:
- build:
- strategy:
- matrix:
- ruby: [2.6]
- runs-on: ubuntu-latest
- name: coverage
- steps:
- - uses: actions/checkout@v2
- - name: Set up Ruby ${{ matrix.ruby }}
- uses: eregon/use-ruby-action@master
- with:
- ruby-version: ${{ matrix.ruby }}
- - name: bundle install
- run: bundle install --jobs 4 --retry 3
- - uses: paambaati/codeclimate-action@v2.4.0
- env:
- CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
- with:
- coverageCommand: bundle exec rake
From f01c72f51a0ee793bfa6aeae1177395e51cd8cde Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:24:13 +0200
Subject: [PATCH 06/31] Create test.yml
---
.github/workflows/test.yml | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 .github/workflows/test.yml
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..bf76132
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,29 @@
+name: CI
+on: [push]
+jobs:
+ build:
+ strategy:
+ matrix:
+ ruby: [2.4, 2.5, 2.6, 2.7]
+ gemfile:
+ - gemfiles/jekyll_4.0.gemfile
+ - gemfiles/jekyll_3.8.gemfile
+ - gemfiles/jekyll_3.7.gemfile
+ exclude:
+ - ruby: 2.4
+ gemfile: gemfiles/jekyll_4.0.gemfile
+ env:
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Ruby ${{ matrix.ruby }}
+ uses: eregon/use-ruby-action@master
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ - name: bundle install
+ run: |
+ gem install bundler
+ bundle install --jobs 4 --retry 3
+ - name: Run Test
+ run: bundle exec rake
From da34e5d24c9ba9665047a4a77e43008d5174dae8 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:24:31 +0200
Subject: [PATCH 07/31] Delete ci.yml
---
.github/workflows/ci.yml | 29 -----------------------------
1 file changed, 29 deletions(-)
delete mode 100644 .github/workflows/ci.yml
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
deleted file mode 100644
index bf76132..0000000
--- a/.github/workflows/ci.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-name: CI
-on: [push]
-jobs:
- build:
- strategy:
- matrix:
- ruby: [2.4, 2.5, 2.6, 2.7]
- gemfile:
- - gemfiles/jekyll_4.0.gemfile
- - gemfiles/jekyll_3.8.gemfile
- - gemfiles/jekyll_3.7.gemfile
- exclude:
- - ruby: 2.4
- gemfile: gemfiles/jekyll_4.0.gemfile
- env:
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Set up Ruby ${{ matrix.ruby }}
- uses: eregon/use-ruby-action@master
- with:
- ruby-version: ${{ matrix.ruby }}
- - name: bundle install
- run: |
- gem install bundler
- bundle install --jobs 4 --retry 3
- - name: Run Test
- run: bundle exec rake
From 357f1b33609d0b25ecc0593884f8d48618e48571 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:26:54 +0200
Subject: [PATCH 08/31] Delete rubocop.yml
---
.github/workflows/rubocop.yml | 19 -------------------
1 file changed, 19 deletions(-)
delete mode 100644 .github/workflows/rubocop.yml
diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml
deleted file mode 100644
index 75338b2..0000000
--- a/.github/workflows/rubocop.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-name: RuboCop
-on: [push]
-jobs:
- build:
- strategy:
- matrix:
- ruby: [2.6]
- runs-on: ubuntu-latest
- name: rubocop
- steps:
- - uses: actions/checkout@v2
- - name: Set up Ruby ${{ matrix.ruby }}
- uses: eregon/use-ruby-action@master
- with:
- ruby-version: ${{ matrix.ruby }}
- - name: bundle install
- run: bundle install --jobs 4 --retry 3
- - name: Run RuboCop
- run: bundle exec rubocop
From c8977a221511f7ed588d49127865e4b7c22a8800 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:28:08 +0200
Subject: [PATCH 09/31] Update test.yml
---
.github/workflows/test.yml | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index bf76132..f1b00df 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,17 +1,12 @@
-name: CI
+name: UnitTest
on: [push]
jobs:
build:
strategy:
matrix:
- ruby: [2.4, 2.5, 2.6, 2.7]
+ ruby: [2.6]
gemfile:
- gemfiles/jekyll_4.0.gemfile
- - gemfiles/jekyll_3.8.gemfile
- - gemfiles/jekyll_3.7.gemfile
- exclude:
- - ruby: 2.4
- gemfile: gemfiles/jekyll_4.0.gemfile
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
runs-on: ubuntu-latest
From 75038187c2cd4e0f5214ccebb6f298b22b3956d3 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:52:20 +0200
Subject: [PATCH 10/31] Update test_inject_anchors_filter.rb
---
test/parser/test_inject_anchors_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index d2f76b0..b4190c5 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -12,7 +12,7 @@ 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)
end
def test_does_not_inject_toc
From 422c996ca428cc35c28b095ebdb4bef377fa51b1 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:53:17 +0200
Subject: [PATCH 11/31] Update test_toc_filter.rb
---
test/parser/test_toc_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index da9edb7..03d5581 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
From 1fc508b854b3fac8bcda6cc846ed5dc3910947b7 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:57:17 +0200
Subject: [PATCH 12/31] Update test_inject_anchors_filter.rb
---
test/parser/test_inject_anchors_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index d2f76b0..b4190c5 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -12,7 +12,7 @@ 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)
end
def test_does_not_inject_toc
From 3d23f2de494682835cb459c4968323ffd827c114 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 09:57:46 +0200
Subject: [PATCH 13/31] Update test_toc_filter.rb
---
test/parser/test_toc_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index da9edb7..03d5581 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
From ef3987fff2d14f92e828ef161bedabcad164ec73 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 10:06:20 +0200
Subject: [PATCH 14/31] Update test_toc_tag.rb
---
test/test_toc_tag.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test_toc_tag.rb b/test/test_toc_tag.rb
index b7f48de..8c65a77 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
From e48bcadf74f9d5257e4056d2ccd48acf96d09836 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 11:44:25 +0200
Subject: [PATCH 15/31] Update test_inject_anchors_filter.rb
---
test/parser/test_inject_anchors_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index b4190c5..c518ac0 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -12,7 +12,7 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html
- assert_match(%r{🔗 Simple H1}, html)
+ assert_match(%r{ExtLinkSimple H1}, html)
end
def test_does_not_inject_toc
From f6c9185e1cfa688b8b0eab50e4b344df9de4bac7 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 11:45:03 +0200
Subject: [PATCH 16/31] Update test_configuration.rb
---
test/test_configuration.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index b32dc58..f0607c2 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -13,7 +13,7 @@ def test_default_conf1guration
assert_equal configuration.sublist_class, ''
assert_equal configuration.item_class, 'toc-entry'
assert_equal configuration.item_prefix, 'toc-'
- assert_equal configuration.inject_anchors_content, '🔗 '
+ assert_equal configuration.inject_anchors_content, 'MyLinkAnchor'
end
def test_type_error
@@ -26,6 +26,6 @@ def test_type_error
assert_equal configuration.sublist_class, ''
assert_equal configuration.item_class, 'toc-entry'
assert_equal configuration.item_prefix, 'toc-'
- assert_equal configuration.inject_anchors_content, '🔗 '
+ assert_equal configuration.inject_anchors_content, 'MyLinkAnchor'
end
-end
\ No newline at end of file
+end
From 9f2993a7b0592de48c5765ad10ba3553bd5f0254 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 11:45:21 +0200
Subject: [PATCH 17/31] Update test_inject_anchors_filter.rb
---
test/parser/test_inject_anchors_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index c518ac0..4562276 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -12,7 +12,7 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html
- assert_match(%r{ExtLinkSimple H1}, html)
+ assert_match(%r{MyLinkAnchorSimple H1}, html)
end
def test_does_not_inject_toc
From 6d6bf32cf3a2b144cad568651f369bb48080ea27 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 11:46:33 +0200
Subject: [PATCH 18/31] Update test_toc_filter.rb
---
test/parser/test_toc_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index 03d5581..d9be297 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{MyLinkAnchorSimple H1}, html)
end
def test_nested_toc
From 864047a8370c053bee86837b2f085108776fe46a Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 12:16:53 +0200
Subject: [PATCH 19/31] Update test_various_toc_html.rb
---
test/parser/test_various_toc_html.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 4c619fe..50c71e0 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -279,9 +279,9 @@ def test_nested_toc_with_no_toc_section_class
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
end
From b6cebfe22961854aae217deb298e784398fdbfc0 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 12:24:10 +0200
Subject: [PATCH 20/31] Fix Unit Tests
---
test/parser/test_inject_anchors_filter.rb | 2 +-
test/parser/test_toc_filter.rb | 2 +-
test/parser/test_various_toc_html.rb | 6 +++---
test/test_toc_tag.rb | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index d2f76b0..4562276 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -12,7 +12,7 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html
- assert_match(%r{Simple H1}, html)
+ assert_match(%r{MyLinkAnchorSimple 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 da9edb7..d9be297 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{MyLinkAnchorSimple 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 4c619fe..50c71e0 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -279,9 +279,9 @@ def test_nested_toc_with_no_toc_section_class
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
end
diff --git a/test/test_toc_tag.rb b/test/test_toc_tag.rb
index b7f48de..8c65a77 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
From 2fd78bd2d0d888c49838916df75e31478634511e Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 13:46:13 +0200
Subject: [PATCH 21/31] Update gitignore with packages
---
.gitignore | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
index 3573f4a..931c8d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,12 @@
+# gems
*.gem
/Gemfile.lock
-/.bundle/
-/coverage
*.gemfile.lock
+/gems/
+
+# tests / test coverage
+/coverage
+
+# bundler
+/.bundle/
+/vendor/bundle/
From 94491329f64056b1ede036349484722f0a05fd65 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 13:47:29 +0200
Subject: [PATCH 22/31] Change default config from unicode to simple text
---
lib/table_of_contents/configuration.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/table_of_contents/configuration.rb b/lib/table_of_contents/configuration.rb
index 481c52a..2bc93e0 100644
--- a/lib/table_of_contents/configuration.rb
+++ b/lib/table_of_contents/configuration.rb
@@ -17,7 +17,7 @@ class Configuration
'sublist_class' => '',
'item_class' => 'toc-entry',
'item_prefix' => 'toc-',
- 'inject_anchors_content' => '🔗 '
+ 'inject_anchors_content' => 'MyLinkAnchor'
}.freeze
def initialize(options)
From 6b0bf747ebaa5914dee41220f1e70194a5065a78 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 14:32:47 +0200
Subject: [PATCH 23/31] Fix Unittests ID in H-element
---
test/parser/test_various_toc_html.rb | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 50c71e0..b56276d 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -320,9 +320,9 @@ def test_nested_toc_with_no_toc_section_class_option
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
assert_includes(html, 'h4
')
assert_includes(html, 'h5
')
@@ -363,9 +363,9 @@ def test_multiple_no_toc_section_classes
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
assert_includes(html, 'h4
')
assert_includes(html, 'h5
')
From 21fd3d6468441300b58aefe24a2563862840b2d4 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 15:45:31 +0200
Subject: [PATCH 24/31] Fix UnitTests
---
test/parser/test_various_toc_html.rb | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 2668b31..f1a15a3 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -279,9 +279,9 @@ def test_nested_toc_with_no_toc_section_class
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
end
@@ -320,9 +320,9 @@ def test_nested_toc_with_no_toc_section_class_option
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
assert_includes(html, 'h4
')
assert_includes(html, 'h5
')
@@ -363,9 +363,9 @@ def test_multiple_no_toc_section_classes
assert_equal(expected, actual)
html = parser.inject_anchors_into_html
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
- assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
+ assert_match(%r{.+
}m, html)
assert_includes(html, 'h2
')
assert_includes(html, 'h4
')
assert_includes(html, 'h5
')
From 77d3b4df21d824140a56d835bdd24448fdbca40f Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 15:53:04 +0200
Subject: [PATCH 25/31] Delete coverage.yml
---
.github/workflows/coverage.yml | 21 ---------------------
1 file changed, 21 deletions(-)
delete mode 100644 .github/workflows/coverage.yml
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
deleted file mode 100644
index 5bc92b4..0000000
--- a/.github/workflows/coverage.yml
+++ /dev/null
@@ -1,21 +0,0 @@
-name: Coverage
-on: [push]
-jobs:
- build:
- strategy:
- matrix:
- ruby: [2.6]
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Set up Ruby ${{ matrix.ruby }}
- uses: eregon/use-ruby-action@master
- with:
- ruby-version: ${{ matrix.ruby }}
- - name: bundle install
- run: bundle install --jobs 4 --retry 3
- - uses: paambaati/codeclimate-action@v2.4.0
- env:
- CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
- with:
- coverageCommand: bundle exec rake
From d339d38b010b9d0e303f15d32e8851de6cb03243 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 15:53:12 +0200
Subject: [PATCH 26/31] Delete rubocop.yml
---
.github/workflows/rubocop.yml | 18 ------------------
1 file changed, 18 deletions(-)
delete mode 100644 .github/workflows/rubocop.yml
diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml
deleted file mode 100644
index bf0d28a..0000000
--- a/.github/workflows/rubocop.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-name: RuboCop
-on: [push]
-jobs:
- build:
- strategy:
- matrix:
- ruby: [2.6]
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Set up Ruby ${{ matrix.ruby }}
- uses: eregon/use-ruby-action@master
- with:
- ruby-version: ${{ matrix.ruby }}
- - name: bundle install
- run: bundle install --jobs 4 --retry 3
- - name: Run RuboCop
- run: bundle exec rubocop
From 1f12d8140014609aff9eaa5d6c64879860ad89bb Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 16:20:22 +0200
Subject: [PATCH 27/31] Add GitHub Actions
---
.github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++
.github/workflows/coverage.yml | 22 ++++++++++++++++++++++
.github/workflows/rubocop.yml | 19 +++++++++++++++++++
3 files changed, 70 insertions(+)
create mode 100644 .github/workflows/ci.yml
create mode 100644 .github/workflows/coverage.yml
create mode 100644 .github/workflows/rubocop.yml
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..539ba59
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,29 @@
+name: CI
+on: [push]
+jobs:
+ build:
+ strategy:
+ matrix:
+ ruby: [2.4, 2.5, 2.6, 2.7]
+ gemfile:
+ - gemfiles/jekyll_4.0.gemfile
+ - gemfiles/jekyll_3.8.gemfile
+ - gemfiles/jekyll_3.7.gemfile
+ exclude:
+ - ruby: 2.4
+ gemfile: gemfiles/jekyll_4.0.gemfile
+ env:
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Ruby ${{ matrix.ruby }}
+ uses: eregon/use-ruby-action@master
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ - name: bundle install
+ run: |
+ gem install bundler
+ bundle install --jobs 4 --retry 3
+ - name: Run Test
+ run: bundle exec rake
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
new file mode 100644
index 0000000..b9cabb9
--- /dev/null
+++ b/.github/workflows/coverage.yml
@@ -0,0 +1,22 @@
+name: Coverage
+on: [push]
+jobs:
+ build:
+ strategy:
+ matrix:
+ ruby: [2.6]
+ runs-on: ubuntu-latest
+ name: coverage
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Ruby ${{ matrix.ruby }}
+ uses: eregon/use-ruby-action@master
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ - name: bundle install
+ run: bundle install --jobs 4 --retry 3
+ - uses: paambaati/codeclimate-action@v2.4.0
+ env:
+ CC_TEST_REPORTER_ID: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
+ with:
+ coverageCommand: bundle exec rake
\ No newline at end of file
diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml
new file mode 100644
index 0000000..cc4538a
--- /dev/null
+++ b/.github/workflows/rubocop.yml
@@ -0,0 +1,19 @@
+name: RuboCop
+on: [push]
+jobs:
+ build:
+ strategy:
+ matrix:
+ ruby: [2.6]
+ runs-on: ubuntu-latest
+ name: rubocop
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Ruby ${{ matrix.ruby }}
+ uses: eregon/use-ruby-action@master
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ - name: bundle install
+ run: bundle install --jobs 4 --retry 3
+ - name: Run RuboCop
+ run: bundle exec rubocop
\ No newline at end of file
From 6f0828a7830cb01c1d0f360b41c184c49a67f404 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 16:30:35 +0200
Subject: [PATCH 28/31] Update .rubocop.yml
---
.rubocop.yml | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/.rubocop.yml b/.rubocop.yml
index 1b2bca9..523762b 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,8 +1,8 @@
AllCops:
TargetRubyVersion: 2.4
Exclude:
- - '*.gemspec'
- - 'gemfiles/*'
+ - "*.gemspec"
+ - "gemfiles/*"
- Rakefile
- Gemfile
@@ -15,14 +15,20 @@ Metrics/AbcSize:
Metrics/ClassLength:
Enabled: false
-Style/BracesAroundHashParameters:
- Enabled: false
-
Style/WordArray:
Enabled: false
Naming/FileName:
Enabled: false
-Layout/LineLength:
+Layout/LineLength:
Enabled: false
+
+Style/HashEachMethods:
+ Enabled: true
+
+Style/HashTransformKeys:
+ Enabled: true
+
+Style/HashTransformValues:
+ Enabled: true
From 03b7a5de32d95c7c0a8d7394b291737ff2661e1e Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 17:44:01 +0200
Subject: [PATCH 29/31] fix rubocop
---
.rubocop.yml | 16 ++++++++++++++++
test/parser/test_inject_anchors_filter.rb | 1 -
test/parser/test_option_error.rb | 1 -
test/parser/test_toc_filter.rb | 1 -
test/parser/test_toc_only_filter.rb | 1 -
test/parser/test_various_toc_html.rb | 1 -
test/test_configuration.rb | 1 -
test/test_helper.rb | 1 -
test/test_jekyll-toc.rb | 1 -
test/test_kramdown_list.rb | 1 -
10 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/.rubocop.yml b/.rubocop.yml
index 523762b..438a1e0 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -3,6 +3,10 @@ AllCops:
Exclude:
- "*.gemspec"
- "gemfiles/*"
+ - /gems/
+ - /vendor/bundle/
+ - gems/
+ - vendor/bundle/
- Rakefile
- Gemfile
@@ -24,6 +28,18 @@ Naming/FileName:
Layout/LineLength:
Enabled: false
+Layout/SpaceAroundMethodCallOperator:
+ Enabled: false
+
+Lint/StructNewOverride:
+ Enabled: false
+
+Lint/RaiseException:
+ Enabled: false
+
+Style/ExponentialNotation:
+ Enabled: false
+
Style/HashEachMethods:
Enabled: true
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index 4562276..dff0623 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestInjectAnchorsFilter < Minitest::Test
diff --git a/test/parser/test_option_error.rb b/test/parser/test_option_error.rb
index 8f85b0b..bb0a784 100644
--- a/test/parser/test_option_error.rb
+++ b/test/parser/test_option_error.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestOptionError < Minitest::Test
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index d9be297..a35e491 100644
--- a/test/parser/test_toc_filter.rb
+++ b/test/parser/test_toc_filter.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestTOCFilter < Minitest::Test
diff --git a/test/parser/test_toc_only_filter.rb b/test/parser/test_toc_only_filter.rb
index 76d7a4d..5afd7ab 100644
--- a/test/parser/test_toc_only_filter.rb
+++ b/test/parser/test_toc_only_filter.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestTOCOnlyFilter < Minitest::Test
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index d5ffad0..0804487 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestVariousTocHtml < Minitest::Test
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index f0607c2..0d82f09 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestConfiguration < Minitest::Test
diff --git a/test/test_helper.rb b/test/test_helper.rb
index d15e386..13d5464 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'simplecov'
SimpleCov.start
diff --git a/test/test_jekyll-toc.rb b/test/test_jekyll-toc.rb
index 634dd47..b0f6820 100644
--- a/test/test_jekyll-toc.rb
+++ b/test/test_jekyll-toc.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestTableOfContentsFilter < Minitest::Test
diff --git a/test/test_kramdown_list.rb b/test/test_kramdown_list.rb
index 60019aa..f663e7e 100644
--- a/test/test_kramdown_list.rb
+++ b/test/test_kramdown_list.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-
require 'test_helper'
class TestKramdownList < Minitest::Test
From 030ea033c484a4f9ee80841672ee2d6c7aaa5f0a Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 18:14:32 +0200
Subject: [PATCH 30/31] rubocop rules
---
.rubocop.yml | 10 ++++++----
lib/table_of_contents/parser.rb | 2 +-
test/parser/test_inject_anchors_filter.rb | 1 +
test/parser/test_option_error.rb | 1 +
test/parser/test_toc_filter.rb | 1 +
test/parser/test_toc_only_filter.rb | 1 +
test/parser/test_various_toc_html.rb | 1 +
test/test_configuration.rb | 1 +
test/test_helper.rb | 1 +
test/test_jekyll-toc.rb | 1 +
test/test_kramdown_list.rb | 1 +
11 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/.rubocop.yml b/.rubocop.yml
index 438a1e0..850ab82 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -3,10 +3,9 @@ AllCops:
Exclude:
- "*.gemspec"
- "gemfiles/*"
- - /gems/
- - /vendor/bundle/
- - gems/
- - vendor/bundle/
+ - gems/**/*
+ - node_modules/**/*
+ - vendor/bundle/**/*
- Rakefile
- Gemfile
@@ -25,6 +24,9 @@ Style/WordArray:
Naming/FileName:
Enabled: false
+Layout/EndOfLine:
+ Enabled: false
+
Layout/LineLength:
Enabled: false
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index c4d5397..8ac7374 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -23,7 +23,7 @@ def build_toc
def inject_anchors_into_html
@entries.each do |entry|
# Add id to h-element
- entry[:header_parent].set_attribute('id', "#{entry[:id]}")
+ entry[:header_parent].set_attribute('id', "#{entry[:id]}.to_s")
entry[:header_content].add_previous_sibling(
%(#{@configuration.inject_anchors_content})
diff --git a/test/parser/test_inject_anchors_filter.rb b/test/parser/test_inject_anchors_filter.rb
index dff0623..4562276 100644
--- a/test/parser/test_inject_anchors_filter.rb
+++ b/test/parser/test_inject_anchors_filter.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestInjectAnchorsFilter < Minitest::Test
diff --git a/test/parser/test_option_error.rb b/test/parser/test_option_error.rb
index bb0a784..8f85b0b 100644
--- a/test/parser/test_option_error.rb
+++ b/test/parser/test_option_error.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestOptionError < Minitest::Test
diff --git a/test/parser/test_toc_filter.rb b/test/parser/test_toc_filter.rb
index a35e491..d9be297 100644
--- a/test/parser/test_toc_filter.rb
+++ b/test/parser/test_toc_filter.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestTOCFilter < Minitest::Test
diff --git a/test/parser/test_toc_only_filter.rb b/test/parser/test_toc_only_filter.rb
index 5afd7ab..76d7a4d 100644
--- a/test/parser/test_toc_only_filter.rb
+++ b/test/parser/test_toc_only_filter.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestTOCOnlyFilter < Minitest::Test
diff --git a/test/parser/test_various_toc_html.rb b/test/parser/test_various_toc_html.rb
index 0804487..d5ffad0 100644
--- a/test/parser/test_various_toc_html.rb
+++ b/test/parser/test_various_toc_html.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestVariousTocHtml < Minitest::Test
diff --git a/test/test_configuration.rb b/test/test_configuration.rb
index 0d82f09..f0607c2 100644
--- a/test/test_configuration.rb
+++ b/test/test_configuration.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestConfiguration < Minitest::Test
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 13d5464..d15e386 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'simplecov'
SimpleCov.start
diff --git a/test/test_jekyll-toc.rb b/test/test_jekyll-toc.rb
index b0f6820..634dd47 100644
--- a/test/test_jekyll-toc.rb
+++ b/test/test_jekyll-toc.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestTableOfContentsFilter < Minitest::Test
diff --git a/test/test_kramdown_list.rb b/test/test_kramdown_list.rb
index f663e7e..60019aa 100644
--- a/test/test_kramdown_list.rb
+++ b/test/test_kramdown_list.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
class TestKramdownList < Minitest::Test
From 2178f417dd8d702c61512099ec14d1cfbc562df1 Mon Sep 17 00:00:00 2001
From: Nicolas Karg <50399433+N7K4@users.noreply.github.com>
Date: Thu, 30 Apr 2020 18:25:33 +0200
Subject: [PATCH 31/31] RuboCop::Cop::Style::RedundantInterpolation
---
lib/table_of_contents/parser.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 8ac7374..ca3159a 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -23,7 +23,7 @@ def build_toc
def inject_anchors_into_html
@entries.each do |entry|
# Add id to h-element
- entry[:header_parent].set_attribute('id', "#{entry[:id]}.to_s")
+ entry[:header_parent].set_attribute('id', entry[:id].to_s)
entry[:header_content].add_previous_sibling(
%(#{@configuration.inject_anchors_content})