jekyll-toc 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2c1e79e71caeb6e93026f4111464e4dc7ac4d8040b7af5c9fe0d5b426c0cfd5
4
- data.tar.gz: c93040f18d95262ce323cbf660a21cd41b1d9afe756bf617f9a434c791d43dcb
3
+ metadata.gz: afa3ea6b7c656558ab8ac87171d113867f0c720a5917d4a057b7754c0f2b1516
4
+ data.tar.gz: 5309a5224a0e925d3993024736821e29d2605fc74c003e9e412ab0af9a26c869
5
5
  SHA512:
6
- metadata.gz: c7b9e1971a2c442d34104a698efe9625b6defa110c6833751b6767ef959d4257ad18ea6b6f9c1f93e756a44daf936eea79a62dd24f638b20621aa91bd7ab2ed2
7
- data.tar.gz: ed6afcf94eeb1813607311b6c5caef82f905314fe5e76bee044a0bdc008692d1218989ae97c9f5c8517154d034d325525c4471b521ca730a89444a0599a5a8e1
6
+ metadata.gz: 0a51b5ea083c92d3cf6842f4d4ab5ec41c8da3425ec8f64c1938933f2e43514eaebd9731a59742bac191990e47318bd72104b92cf8611a97d3858d21c390db74
7
+ data.tar.gz: 34b863397e58393a41d567a412a84676ac125fa5ad3465a509114ad0b965f3d440ef3a730f81d96313b6f76beb3c8529a610702ca667489fa012fd4dfd76125d
data/.travis.yml CHANGED
@@ -7,12 +7,12 @@ rvm:
7
7
  - 2.3.7
8
8
  - 2.4.4
9
9
  - 2.5.1
10
+ - 2.6.2
10
11
  # gemfile is generated by appraisal
11
12
  gemfile:
12
13
  - gemfiles/jekyll_3.8.gemfile
13
14
  - gemfiles/jekyll_3.7.gemfile
14
15
  - gemfiles/jekyll_3.6.gemfile
15
- - gemfiles/jekyll_3.5.gemfile
16
16
  before_script:
17
17
  # Download cc-test-reporter
18
18
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
data/Appraisals CHANGED
@@ -11,7 +11,3 @@ end
11
11
  appraise 'jekyll-3.6' do
12
12
  gem 'jekyll', '3.6'
13
13
  end
14
-
15
- appraise 'jekyll-3.5' do
16
- gem 'jekyll', '3.5'
17
- end
data/jekyll-toc.gemspec CHANGED
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency 'appraisal'
23
23
  spec.add_development_dependency 'jekyll', '>= 3.5'
24
- spec.add_development_dependency 'minitest', '~> 5.0'
24
+ spec.add_development_dependency 'minitest', '~> 5.11'
25
+ spec.add_development_dependency 'minitest-reporters'
25
26
  spec.add_development_dependency 'pry'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'rubocop'
@@ -39,8 +39,8 @@ module Jekyll
39
39
 
40
40
  def inject_anchors_into_html
41
41
  @entries.each do |entry|
42
- entry[:content_node].add_previous_sibling(
43
- %(<a id="#{entry[:id]}#{entry[:uniq]}" class="anchor" href="##{entry[:id]}#{entry[:uniq]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>)
42
+ entry[:header_content].add_previous_sibling(
43
+ %(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>)
44
44
  )
45
45
  end
46
46
 
@@ -63,17 +63,14 @@ module Jekyll
63
63
  .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
64
64
  .tr(' ', '-') # replace spaces with dash
65
65
 
66
- uniq = headers[id].positive? ? "-#{headers[id]}" : ''
66
+ suffix_num = headers[id]
67
67
  headers[id] += 1
68
- header_content = node.children.first
69
- next entries unless header_content
70
68
 
71
69
  entries << {
72
- id: id,
73
- uniq: uniq,
70
+ id: suffix_num.zero? ? id : "#{id}-#{suffix_num}",
74
71
  text: CGI.escapeHTML(text),
75
72
  node_name: node.name,
76
- content_node: header_content,
73
+ header_content: node.children.first,
77
74
  h_num: node.name.delete('h').to_i
78
75
  }
79
76
  end
@@ -89,7 +86,7 @@ module Jekyll
89
86
  entry = entries[i]
90
87
  if entry[:h_num] == min_h_num
91
88
  # If the current entry should not be indented in the list, add the entry to the list
92
- toc_list << %(<li class="#{@item_class} #{@item_prefix}#{entry[:node_name]}"><a href="##{entry[:id]}#{entry[:uniq]}">#{entry[:text]}</a>)
89
+ toc_list << %(<li class="#{@item_class} #{@item_prefix}#{entry[:node_name]}"><a href="##{entry[:id]}">#{entry[:text]}</a>)
93
90
  # If the next entry should be indented in the list, generate a sublist
94
91
  next_i = i + 1
95
92
  if next_i < entries.count && entries[next_i][:h_num] > min_h_num
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllToc
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
@@ -12,7 +12,7 @@ class TestInjectAnchorsFilter < Minitest::Test
12
12
  def test_injects_anchors_into_content
13
13
  html = @parser.inject_anchors_into_html
14
14
 
15
- assert_match(%r{<a id="simple-h1" class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
15
+ assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
16
16
  end
17
17
 
18
18
  def test_does_not_inject_toc
@@ -12,7 +12,7 @@ class TestTOCFilter < Minitest::Test
12
12
  def test_injects_anchors
13
13
  html = @parser.toc
14
14
 
15
- assert_match(%r{<a id="simple-h1" class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
15
+ assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
16
16
  end
17
17
 
18
18
  def test_nested_toc
@@ -391,9 +391,30 @@ class TestVariousTocHtml < Minitest::Test
391
391
  assert_equal(expected, actual)
392
392
 
393
393
  html = parser.inject_anchors_into_html
394
- assert_includes(html, %(<a id="h1" class="anchor" href="#h1" aria-hidden="true">))
395
- assert_includes(html, %(<a id="second" class="anchor" href="#second" aria-hidden="true">))
396
- assert_includes(html, %(<a id="third" class="anchor" href="#third" aria-hidden="true">))
394
+ assert_includes(html, %(<a class="anchor" href="#h1" aria-hidden="true">))
395
+ assert_includes(html, %(<a class="anchor" href="#second" aria-hidden="true">))
396
+ assert_includes(html, %(<a class="anchor" href="#third" aria-hidden="true">))
397
+ end
398
+
399
+
400
+ TEST_UNIQ_ID = <<~HTML
401
+ <h1>h1</h1>
402
+ <h1>h1</h1>
403
+ <h1>h1</h1>
404
+ HTML
405
+
406
+ def test_anchor_is_uniq
407
+ parser = Jekyll::TableOfContents::Parser.new(TEST_UNIQ_ID)
408
+ doc = Nokogiri::HTML(parser.toc)
409
+ expected = <<~HTML
410
+ <ul class="section-nav">
411
+ <li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
412
+ <li class="toc-entry toc-h1"><a href="#h1-1">h1</a></li>
413
+ <li class="toc-entry toc-h1"><a href="#h1-2">h1</a></li>
414
+ </ul>
415
+ HTML
416
+ actual = doc.css('ul.section-nav').to_s
417
+ assert_equal(expected, actual)
397
418
  end
398
419
 
399
420
  def test_custom_css_classes
data/test/test_helper.rb CHANGED
@@ -4,6 +4,9 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'minitest/autorun'
7
+ require "minitest/reporters"
8
+ Minitest::Reporters.use!
9
+
7
10
  require 'jekyll'
8
11
  require 'jekyll-toc'
9
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-toc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - toshimaru
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-23 00:00:00.000000000 Z
12
+ date: 2019-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -59,14 +59,28 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '5.0'
62
+ version: '5.11'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '5.0'
69
+ version: '5.11'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest-reporters
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: pry
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +152,6 @@ files:
138
152
  - LICENSE.md
139
153
  - README.md
140
154
  - Rakefile
141
- - gemfiles/jekyll_3.5.gemfile
142
155
  - gemfiles/jekyll_3.6.gemfile
143
156
  - gemfiles/jekyll_3.7.gemfile
144
157
  - gemfiles/jekyll_3.8.gemfile
@@ -146,14 +159,14 @@ files:
146
159
  - lib/jekyll-toc.rb
147
160
  - lib/table_of_contents/parser.rb
148
161
  - lib/version.rb
162
+ - test/parser/test_inject_anchors_filter.rb
163
+ - test/parser/test_option_error.rb
164
+ - test/parser/test_toc_filter.rb
165
+ - test/parser/test_toc_only_filter.rb
166
+ - test/parser/test_various_toc_html.rb
149
167
  - test/test_helper.rb
150
- - test/test_inject_anchors_filter.rb
151
168
  - test/test_jekyll-toc.rb
152
169
  - test/test_kramdown_list.rb
153
- - test/test_option_error.rb
154
- - test/test_toc_filter.rb
155
- - test/test_toc_only_filter.rb
156
- - test/test_various_toc_html.rb
157
170
  homepage: https://github.com/toshimaru/jekyll-toc
158
171
  licenses:
159
172
  - MIT
@@ -178,11 +191,11 @@ signing_key:
178
191
  specification_version: 4
179
192
  summary: Jekyll Table of Contents plugin
180
193
  test_files:
194
+ - test/parser/test_inject_anchors_filter.rb
195
+ - test/parser/test_option_error.rb
196
+ - test/parser/test_toc_filter.rb
197
+ - test/parser/test_toc_only_filter.rb
198
+ - test/parser/test_various_toc_html.rb
181
199
  - test/test_helper.rb
182
- - test/test_inject_anchors_filter.rb
183
200
  - test/test_jekyll-toc.rb
184
201
  - test/test_kramdown_list.rb
185
- - test/test_option_error.rb
186
- - test/test_toc_filter.rb
187
- - test/test_toc_only_filter.rb
188
- - test/test_various_toc_html.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "jekyll", "3.5"
6
-
7
- gemspec path: "../"