jekyll-toc 0.7.0.beta1 → 0.7.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: 2b7578981ba66427ed37a31d9705ad0e174d5646d31f5cd028fbe28038249a83
4
- data.tar.gz: 63cfa7ca781467175dea8072975b41416fc556e2e4fa3c0f77f741ff0746c401
3
+ metadata.gz: bf842397d274621c986cf5182baaed15cff4f406e309741621ca897545525cf0
4
+ data.tar.gz: ac1181c4a77d63773b6fa12d3b646582b01e77aba41104291cf8c2bff3a6babb
5
5
  SHA512:
6
- metadata.gz: 639bb631c1370b4c0f01f5769fa79048f883603d9582441d2c7d214e89bd2e578d6c174b72c48d5d1acaf52e496fe59332c8b6626eb4b1786c1ee6934bcce542
7
- data.tar.gz: 120b7f1bafb23b34c99149d4db56418644e9918b436a9753ecf07ac5cabb19a3410eac999785277cc38bf6e3a88de2bc84efbac4e3162485250d460affcc5d92
6
+ metadata.gz: f01826275203ce38ebdc8d8ce427e91bf9f8e1c4e437803caf5a3073fe44e5cdc4b022f4319199ec3eeca2b834cf8a282bfd38843bfb5d7bd918958c90994722
7
+ data.tar.gz: 0df513610cb1aa29706f069404424d66d0e50252b3df93254c8419cf7a297497b96eb9ba33506b53f3f56681950f4f14881fb3156e2f50713d708ee4fe4d8e9e
data/README.md CHANGED
@@ -5,6 +5,16 @@
5
5
  [![Code Climate](https://codeclimate.com/github/toshimaru/jekyll-toc/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/jekyll-toc)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/toshimaru/jekyll-toc/test_coverage)
7
7
 
8
+ # Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Generated HTML](#generated-html)
13
+ - [Customization](#customization)
14
+ - [Skip TOC](#skip-toc)
15
+ - [TOC levels](#toc-levels)
16
+ - [CSS Styling](#css-styling)
17
+
8
18
  # Installation
9
19
 
10
20
  Add jekyll-toc plugin in your site's `Gemfile`, and run `bundle install`.
@@ -73,6 +83,8 @@ location with the `toc_only` filter.
73
83
 
74
84
  ## Generated HTML
75
85
 
86
+ ![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
87
+
76
88
  jekyll-toc generates an unordered list. The HTML output is as follows.
77
89
 
78
90
  ```html
@@ -97,13 +109,9 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
97
109
  </ul>
98
110
  ```
99
111
 
100
- It looks like the image below.
101
-
102
- ![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
103
-
104
112
  ## Customization
105
113
 
106
- ### Skip TOC(`no_toc`)
114
+ ### Skip TOC
107
115
 
108
116
  The heding is ignored in the toc when you add `no_toc` to the class.
109
117
 
@@ -113,7 +121,7 @@ The heding is ignored in the toc when you add `no_toc` to the class.
113
121
  <h2>h2</h2>
114
122
  ```
115
123
 
116
- ### TOC level
124
+ ### TOC levels
117
125
 
118
126
  The toc levels can be configured on `_config.yml`.
119
127
 
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def build_toc
22
- %(<ul class="section-nav">\n#{build_toc_list(@entries, last_ul_used: true)}</ul>)
22
+ %(<ul class="section-nav">\n#{build_toc_list(@entries)}</ul>)
23
23
  end
24
24
 
25
25
  def inject_anchors_into_html
@@ -68,7 +68,7 @@ module Jekyll
68
68
  end
69
69
 
70
70
  # Returns the list items for entries
71
- def build_toc_list(entries, last_ul_used: false)
71
+ def build_toc_list(entries)
72
72
  i = 0
73
73
  toc_list = ''.dup
74
74
  min_h_num = entries.map { |e| e[:h_num] }.min
@@ -83,7 +83,7 @@ module Jekyll
83
83
  next_entry = entries[i + 1]
84
84
  if next_entry[:h_num] > min_h_num
85
85
  nest_entries = get_nest_entries(entries[i + 1, entries.count], min_h_num)
86
- toc_list << %(\n<ul>\n#{build_toc_list(nest_entries, last_ul_used: true)}</ul>\n)
86
+ toc_list << %(\n<ul>\n#{build_toc_list(nest_entries)}</ul>\n)
87
87
  i += nest_entries.count
88
88
  end
89
89
  end
@@ -92,11 +92,7 @@ module Jekyll
92
92
  elsif entry[:h_num] > min_h_num
93
93
  # If the current entry should be indented in the list, generate a sublist
94
94
  nest_entries = get_nest_entries(entries[i, entries.count], min_h_num)
95
- if last_ul_used
96
- toc_list << build_toc_list(nest_entries, last_ul_used: true)
97
- else
98
- toc_list << %(<ul>\n#{build_toc_list(nest_entries, last_ul_used: true)}</ul>\n)
99
- end
95
+ toc_list << build_toc_list(nest_entries)
100
96
  i += nest_entries.count - 1
101
97
  end
102
98
  i += 1
@@ -116,7 +112,7 @@ module Jekyll
116
112
  end
117
113
 
118
114
  def toc_headings
119
- @toc_levels.map { |level| "h#{level}" }.join(",")
115
+ @toc_levels.map { |level| "h#{level}" }.join(',')
120
116
  end
121
117
 
122
118
  def generate_option_hash(options)
@@ -1,3 +1,3 @@
1
1
  module JekyllToc
2
- VERSION = '0.7.0.beta1'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -4,7 +4,6 @@ require 'test_helper'
4
4
 
5
5
  class TestKramdownList < Minitest::Test
6
6
  # NOTE: kramdown automatically injects `id` attribute
7
- # TODO: test Japanese heading
8
7
  def test_kramdown_heading
9
8
  text = <<-MARKDOWN
10
9
  # h1
@@ -14,10 +13,27 @@ class TestKramdownList < Minitest::Test
14
13
  expected = <<-HTML
15
14
  <h1 id="h1">h1</h1>
16
15
 
17
- <h2 id=\"h2\">h2</h2>
16
+ <h2 id="h2">h2</h2>
18
17
  HTML
18
+ actual = Kramdown::Document.new(text).to_html
19
19
 
20
- assert_equal(expected, Kramdown::Document.new(text).to_html)
20
+ assert_equal(expected, actual)
21
+ end
22
+
23
+ def test_japanese_heading
24
+ text = <<-MARKDOWN
25
+ # 日本語見出し1
26
+
27
+ ## 日本語見出し2
28
+ MARKDOWN
29
+ expected = <<-HTML
30
+ <h1 id="section">日本語見出し1</h1>
31
+
32
+ <h2 id="section-1">日本語見出し2</h2>
33
+ HTML
34
+ actual = Kramdown::Document.new(text).to_html
35
+
36
+ assert_equal(expected, actual)
21
37
  end
22
38
 
23
39
  def test_kramdown_list_1
@@ -49,8 +65,9 @@ class TestKramdownList < Minitest::Test
49
65
  </li>
50
66
  </ul>
51
67
  HTML
68
+ actual = Kramdown::Document.new(text).to_html
52
69
 
53
- assert_equal(expected, Kramdown::Document.new(text).to_html)
70
+ assert_equal(expected, actual)
54
71
  end
55
72
 
56
73
  def test_kramdown_list_2
@@ -79,8 +96,9 @@ class TestKramdownList < Minitest::Test
79
96
  </li>
80
97
  </ul>
81
98
  HTML
99
+ actual = Kramdown::Document.new(text).to_html
82
100
 
83
- assert_equal(expected, Kramdown::Document.new(text).to_html)
101
+ assert_equal(expected, actual)
84
102
  end
85
103
 
86
104
  def test_kramdown_list_3
@@ -95,8 +113,9 @@ class TestKramdownList < Minitest::Test
95
113
  * level-3 * level-2 * level-1
96
114
  </code></pre>
97
115
  HTML
116
+ actual = Kramdown::Document.new(text).to_html
98
117
 
99
- assert_equal(expected, Kramdown::Document.new(text).to_html)
118
+ assert_equal(expected, actual)
100
119
  end
101
120
 
102
121
  def test_kramdown_list_4
@@ -119,18 +138,19 @@ class TestKramdownList < Minitest::Test
119
138
  <li>level-1</li>
120
139
  </ul>
121
140
  HTML
141
+ actual = Kramdown::Document.new(text).to_html
122
142
 
123
- assert_equal(expected, Kramdown::Document.new(text).to_html)
143
+ assert_equal(expected, actual)
124
144
  end
125
145
 
126
- def test_kramdown_list_5
127
- text = <<-MARKDOWN
146
+ def test_kramdown_list_5
147
+ text = <<-MARKDOWN
128
148
  * level-1
129
149
  * level-3
130
150
  * level-2
131
151
  * level-1
132
- MARKDOWN
133
- expected = <<-HTML
152
+ MARKDOWN
153
+ expected = <<-HTML
134
154
  <ul>
135
155
  <li>level-1
136
156
  <ul>
@@ -140,8 +160,9 @@ class TestKramdownList < Minitest::Test
140
160
  </li>
141
161
  <li>level-1</li>
142
162
  </ul>
143
- HTML
163
+ HTML
164
+ actual = Kramdown::Document.new(text).to_html
144
165
 
145
- assert_equal(expected, Kramdown::Document.new(text).to_html)
146
- end
166
+ assert_equal(expected, actual)
167
+ end
147
168
  end
@@ -3,7 +3,7 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class TestOptionError < Minitest::Test
6
- BASE_HTML = "<h1>h1</h1>"
6
+ BASE_HTML = '<h1>h1</h1>'
7
7
  EXPECTED_HTML = <<-HTML
8
8
  <ul class="section-nav">
9
9
  <li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
@@ -18,14 +18,14 @@ class TestOptionError < Minitest::Test
18
18
  end
19
19
 
20
20
  def test_option_is_epmty_string
21
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, "")
21
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, '')
22
22
  doc = Nokogiri::HTML(parser.toc)
23
23
  expected = EXPECTED_HTML
24
24
  assert_equal(expected, doc.css('ul.section-nav').to_s)
25
25
  end
26
26
 
27
27
  def test_option_is_string
28
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, "string")
28
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, 'string')
29
29
  doc = Nokogiri::HTML(parser.toc)
30
30
  expected = EXPECTED_HTML
31
31
  assert_equal(expected, doc.css('ul.section-nav').to_s)
@@ -44,6 +44,12 @@ class TestVariousTocHtml < Minitest::Test
44
44
  <h4 class="no_toc">no_toc h4</h4>
45
45
  HTML
46
46
 
47
+ TEST_JAPANESE_HTML = <<-HTML
48
+ <h1>あ</h1>
49
+ <h2>い</h2>
50
+ <h3>う</h3>
51
+ HTML
52
+
47
53
  def test_nested_toc
48
54
  parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
49
55
  doc = Nokogiri::HTML(parser.toc)
@@ -177,4 +183,27 @@ class TestVariousTocHtml < Minitest::Test
177
183
 
178
184
  assert_equal(expected, actual)
179
185
  end
186
+
187
+ def test_japanese_toc
188
+ parser = Jekyll::TableOfContents::Parser.new(TEST_JAPANESE_HTML)
189
+ doc = Nokogiri::HTML(parser.toc)
190
+ expected = <<-HTML
191
+ <ul class="section-nav">
192
+ <li class="toc-entry toc-h1">
193
+ <a href="#%E3%81%82">あ</a>
194
+ <ul>
195
+ <li class="toc-entry toc-h2">
196
+ <a href="#%E3%81%84">い</a>
197
+ <ul>
198
+ <li class="toc-entry toc-h3"><a href="#%E3%81%86">う</a></li>
199
+ </ul>
200
+ </li>
201
+ </ul>
202
+ </li>
203
+ </ul>
204
+ HTML
205
+ actual = doc.css('ul.section-nav').to_s
206
+
207
+ assert_equal(expected, actual)
208
+ end
180
209
  end
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.7.0.beta1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - toshimaru
@@ -153,9 +153,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: 2.2.2
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ">"
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 1.3.1
158
+ version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
161
  rubygems_version: 2.7.6