jekyll-toc 0.8.0 → 0.9.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4467af27a06bb26975169fc6b483ac6b9cf7dc193d957a4d1802018f3e538ea9
4
- data.tar.gz: 78d9f36a92f6d5329476fe348cbbcae64bf5174762934324a093e65a24d19aee
3
+ metadata.gz: e065b97dcb3e794963823391777d7f7b18858c3bf40ee47a9266f695c2306cb5
4
+ data.tar.gz: f2be7aea0ba994d5aa8348f37c0d85080dcd9aebfa7d2e8ec9e1611802efacf7
5
5
  SHA512:
6
- metadata.gz: 5a3b28995adb47063335b775d389472b0b1584fde3818b134e76792da6e20c7bfe4a86ef2afe1b038c3f8de8128d92d87e6f14a816fef5dacc58fe13f76c1982
7
- data.tar.gz: 8e27495a54ea17a012e3027464bee31a26e954d91fdb7a0e807c5b13f99baeb29c1461a2f9aea8de2fa966a4e041b3a7897e1f1c0e4c22ecb44c9db312bf0b19
6
+ metadata.gz: 14af1dc403067ef8ce268acbdb7f6a8af5712be0f8d59f77736dfd46ff31607c5073595c5d984c336022202f41e62c8d72128e9a86865c6d80092026ae06008a
7
+ data.tar.gz: e396d673df7bad05f79cf218b49ab690e275b3ec943821c5b7e65387f7ac3c8226bee0cc13555cbbead5bf7f8d9685ea4d41559c49a77e96d1987b77d16a0018
data/README.md CHANGED
@@ -154,6 +154,20 @@ toc:
154
154
  max_level: 5 # default: 6
155
155
  ```
156
156
 
157
+ You can apply custom CSS classes to the generated `<ul>` and `<li>` tags.
158
+
159
+ ```yml
160
+ toc:
161
+ # Default is "section-nav":
162
+ list_class: my-list-class
163
+ # Default is no class for sublists:
164
+ sublist_class: my-sublist-class
165
+ # Default is "toc-entry":
166
+ item_class: my-item-class
167
+ # Default is "toc-":
168
+ item_prefix: item-
169
+ ```
170
+
157
171
  The default level range is `<h1>` to `<h6>`.
158
172
 
159
173
  #### CSS Styling
@@ -10,7 +10,11 @@ module Jekyll
10
10
  DEFAULT_CONFIG = {
11
11
  'no_toc_section_class' => 'no_toc_section',
12
12
  'min_level' => 1,
13
- 'max_level' => 6
13
+ 'max_level' => 6,
14
+ "list_class" => "section-nav",
15
+ "sublist_class" => "",
16
+ "item_class" => "toc-entry",
17
+ "item_prefix" => "toc-"
14
18
  }.freeze
15
19
 
16
20
  def initialize(html, options = {})
@@ -18,6 +22,10 @@ module Jekyll
18
22
  options = generate_option_hash(options)
19
23
  @toc_levels = options['min_level']..options['max_level']
20
24
  @no_toc_section_class = options['no_toc_section_class']
25
+ @list_class = options["list_class"]
26
+ @sublist_class = options["sublist_class"]
27
+ @item_class = options["item_class"]
28
+ @item_prefix = options["item_prefix"]
21
29
  @entries = parse_content
22
30
  end
23
31
 
@@ -26,7 +34,7 @@ module Jekyll
26
34
  end
27
35
 
28
36
  def build_toc
29
- %(<ul class="section-nav">\n#{build_toc_list(@entries)}</ul>)
37
+ %(<ul class="#{@list_class}">\n#{build_toc_list(@entries)}</ul>)
30
38
  end
31
39
 
32
40
  def inject_anchors_into_html
@@ -77,15 +85,16 @@ module Jekyll
77
85
 
78
86
  while i < entries.count
79
87
  entry = entries[i]
88
+ ul_attributes = @sublist_class.empty? ? "" : %( class="#{@sublist_class}")
80
89
  if entry[:h_num] == min_h_num
81
90
  # If the current entry should not be indented in the list, add the entry to the list
82
- toc_list << %(<li class="toc-entry toc-#{entry[:node_name]}"><a href="##{entry[:id]}#{entry[:uniq]}">#{entry[:text]}</a>)
91
+ toc_list << %(<li class="#{@item_class} #{@item_prefix}#{entry[:node_name]}"><a href="##{entry[:id]}#{entry[:uniq]}">#{entry[:text]}</a>)
83
92
  # If the next entry should be indented in the list, generate a sublist
84
93
  if i + 1 < entries.count
85
94
  next_entry = entries[i + 1]
86
95
  if next_entry[:h_num] > min_h_num
87
96
  nest_entries = get_nest_entries(entries[i + 1, entries.count], min_h_num)
88
- toc_list << %(\n<ul>\n#{build_toc_list(nest_entries)}</ul>\n)
97
+ toc_list << %(\n<ul#{ul_attributes}>\n#{build_toc_list(nest_entries)}</ul>\n)
89
98
  i += nest_entries.count
90
99
  end
91
100
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllToc
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.9.0.beta1'.freeze
3
3
  end
@@ -353,3 +353,25 @@ class TestVariousTocHtml < Minitest::Test
353
353
  assert_includes(html, %(<a id="third" class="anchor" href="#third" aria-hidden="true">))
354
354
  end
355
355
  end
356
+
357
+ def test_custom_css_classes
358
+ parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1, { "item_class" => "custom-item", "list_class" => "custom-list", "sublist_class" => "custom-sublist", "item_prefix" => "custom-prefix-" })
359
+ doc = Nokogiri::HTML(parser.toc)
360
+ expected = <<-HTML
361
+ <ul class="custom-list">
362
+ <li class="custom-item custom-prefix-h1">
363
+ <a href="#h1">h1</a>
364
+ <ul class="custom-sublist">
365
+ <li class="custom-item custom-prefix-h3">
366
+ <a href="#h3">h3</a>
367
+ <ul class="custom-sublist">
368
+ <li class="custom-item custom-prefix-h6"><a href="#h6">h6</a></li>
369
+ </ul>
370
+ </li>
371
+ </ul>
372
+ </li>
373
+ </ul>
374
+ HTML
375
+
376
+ assert_equal(expected, doc.css('ul.custom-list').to_s)
377
+ 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.8.0
4
+ version: 0.9.0.beta1
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: '0'
158
+ version: 1.3.1
159
159
  requirements: []
160
160
  rubyforge_project:
161
161
  rubygems_version: 2.7.6