Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/empty links #181

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/table_of_contents/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Configuration
def initialize(options)
options = generate_option_hash(options)

@toc_levels = options['min_level']..options['max_level']
@toc_levels = (options['min_level']..options['max_level']).to_a
@ordered_list = options['ordered_list']
@no_toc_class = 'no_toc'
@no_toc_section_class = options['no_toc_section_class']
@no_toc_section_class = Array(options['no_toc_section_class'])
@list_id = options['list_id']
@list_class = options['list_class']
@sublist_class = options['sublist_class']
Expand Down
6 changes: 1 addition & 5 deletions lib/table_of_contents/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ 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(
%(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>)
)
entry[:header_content].wrap(%(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>))
end

@doc.inner_html
end

Expand Down
3 changes: 2 additions & 1 deletion test/parser/test_inject_anchors_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html

assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span>Simple H1</a>}, html)
end


def test_does_not_inject_toc
html = @parser.inject_anchors_into_html
Expand Down
2 changes: 1 addition & 1 deletion test/parser/test_toc_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup
def test_injects_anchors
html = @parser.toc

assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span>Simple H1</a>}, html)
end

def test_nested_toc
Expand Down
6 changes: 3 additions & 3 deletions test/parser/test_various_toc_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def test_japanese_toc
assert_equal(expected, parser.build_toc)
html_with_anchors = parser.inject_anchors_into_html

assert_match(%r{<a class="anchor" href="#%E3%81%82" aria-hidden="true"><span.*span></a>}, html_with_anchors)
assert_match(%r{<a class="anchor" href="#%E3%81%84" aria-hidden="true"><span.*span></a>}, html_with_anchors)
assert_match(%r{<a class="anchor" href="#%E3%81%86" aria-hidden="true"><span.*span></a>}, html_with_anchors)
assert_match(%r{<a class="anchor" href="#%E3%81%82" aria-hidden="true"><span.*span></a>}, html_with_anchors)
assert_match(%r{<a class="anchor" href="#%E3%81%84" aria-hidden="true"><span.*span></a>}, html_with_anchors)
assert_match(%r{<a class="anchor" href="#%E3%81%86" aria-hidden="true"><span.*span></a>}, html_with_anchors)
end

# ref. https://github.com/toshimaru/jekyll-toc/issues/45
Expand Down
8 changes: 4 additions & 4 deletions test/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class TestConfiguration < Minitest::Test
def test_default_configuration
configuration = Jekyll::TableOfContents::Configuration.new({})

assert_equal(1..6, configuration.toc_levels)
assert_equal((1..6).to_a, configuration.toc_levels)
refute(configuration.ordered_list)
assert_equal('no_toc_section', configuration.no_toc_section_class)
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)
Expand All @@ -19,9 +19,9 @@ def test_default_configuration
def test_type_error
configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')

assert_equal(1..6, configuration.toc_levels)
assert_equal((1..6).to_a, configuration.toc_levels)
refute(configuration.ordered_list)
assert_equal('no_toc_section', configuration.no_toc_section_class)
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)
Expand Down