diff --git a/README.md b/README.md
index 9116fa4..78b6930 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,16 @@
[![Code Climate](https://codeclimate.com/github/toshimaru/jekyll-toc/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/jekyll-toc)
[![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/toshimaru/jekyll-toc/test_coverage)
+# Table of Contents
+
+- [Installation](#installation)
+- [Usage](#usage)
+- [Generated HTML](#generated-html)
+- [Customization](#customization)
+ - [Skip TOC](#skip-toc)
+ - [TOC levels](#toc-levels)
+ - [CSS Styling](#css-styling)
+
# Installation
Add jekyll-toc plugin in your site's `Gemfile`, and run `bundle install`.
@@ -73,6 +83,8 @@ location with the `toc_only` filter.
## Generated HTML
+![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
+
jekyll-toc generates an unordered list. The HTML output is as follows.
```html
@@ -97,13 +109,9 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
```
-It looks like the image below.
-
-![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)
-
## Customization
-### Skip TOC(`no_toc`)
+### Skip TOC
The heding is ignored in the toc when you add `no_toc` to the class.
@@ -113,7 +121,7 @@ The heding is ignored in the toc when you add `no_toc` to the class.
h2
```
-### TOC level
+### TOC levels
The toc levels can be configured on `_config.yml`.
diff --git a/lib/table_of_contents/parser.rb b/lib/table_of_contents/parser.rb
index 8857e3c..b032abb 100644
--- a/lib/table_of_contents/parser.rb
+++ b/lib/table_of_contents/parser.rb
@@ -19,7 +19,7 @@ def initialize(html, options = {})
end
def build_toc
- %(\n#{build_toc_list(@entries, last_ul_used: true)}
)
+ %(\n#{build_toc_list(@entries)}
)
end
def inject_anchors_into_html
@@ -68,7 +68,7 @@ def parse_content
end
# Returns the list items for entries
- def build_toc_list(entries, last_ul_used: false)
+ def build_toc_list(entries)
i = 0
toc_list = ''.dup
min_h_num = entries.map { |e| e[:h_num] }.min
@@ -83,7 +83,7 @@ def build_toc_list(entries, last_ul_used: false)
next_entry = entries[i + 1]
if next_entry[:h_num] > min_h_num
nest_entries = get_nest_entries(entries[i + 1, entries.count], min_h_num)
- toc_list << %(\n\n#{build_toc_list(nest_entries, last_ul_used: true)}
\n)
+ toc_list << %(\n\n#{build_toc_list(nest_entries)}
\n)
i += nest_entries.count
end
end
@@ -92,11 +92,7 @@ def build_toc_list(entries, last_ul_used: false)
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)
- if last_ul_used
- toc_list << build_toc_list(nest_entries, last_ul_used: true)
- else
- toc_list << %(\n#{build_toc_list(nest_entries, last_ul_used: true)}
\n)
- end
+ toc_list << build_toc_list(nest_entries)
i += nest_entries.count - 1
end
i += 1
@@ -116,7 +112,7 @@ def get_nest_entries(entries, min_h_num)
end
def toc_headings
- @toc_levels.map { |level| "h#{level}" }.join(",")
+ @toc_levels.map { |level| "h#{level}" }.join(',')
end
def generate_option_hash(options)
diff --git a/lib/version.rb b/lib/version.rb
index 287676f..8c3dc03 100644
--- a/lib/version.rb
+++ b/lib/version.rb
@@ -1,3 +1,3 @@
module JekyllToc
- VERSION = '0.7.0.beta1'.freeze
+ VERSION = '0.7.0'.freeze
end
diff --git a/test/test_kramdown_list.rb b/test/test_kramdown_list.rb
index 7df81fa..7196703 100644
--- a/test/test_kramdown_list.rb
+++ b/test/test_kramdown_list.rb
@@ -4,7 +4,6 @@
class TestKramdownList < Minitest::Test
# NOTE: kramdown automatically injects `id` attribute
- # TODO: test Japanese heading
def test_kramdown_heading
text = <<-MARKDOWN
# h1
@@ -14,10 +13,27 @@ def test_kramdown_heading
expected = <<-HTML
h1
-h2
+h2
HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
+ assert_equal(expected, actual)
+ end
+
+ def test_japanese_heading
+ text = <<-MARKDOWN
+# 日本語見出し1
+
+## 日本語見出し2
+ MARKDOWN
+ expected = <<-HTML
+日本語見出し1
+
+日本語見出し2
+ HTML
+ actual = Kramdown::Document.new(text).to_html
+
+ assert_equal(expected, actual)
end
def test_kramdown_list_1
@@ -49,8 +65,9 @@ def test_kramdown_list_1
HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
+ assert_equal(expected, actual)
end
def test_kramdown_list_2
@@ -79,8 +96,9 @@ def test_kramdown_list_2
HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
+ assert_equal(expected, actual)
end
def test_kramdown_list_3
@@ -95,8 +113,9 @@ def test_kramdown_list_3
* level-3 * level-2 * level-1
HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
+ assert_equal(expected, actual)
end
def test_kramdown_list_4
@@ -119,18 +138,19 @@ def test_kramdown_list_4
level-1
HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
+ assert_equal(expected, actual)
end
- def test_kramdown_list_5
- text = <<-MARKDOWN
+ def test_kramdown_list_5
+ text = <<-MARKDOWN
* level-1
* level-3
* level-2
* level-1
- MARKDOWN
- expected = <<-HTML
+ MARKDOWN
+ expected = <<-HTML
- level-1
@@ -140,8 +160,9 @@ def test_kramdown_list_5
- level-1
- HTML
+ HTML
+ actual = Kramdown::Document.new(text).to_html
- assert_equal(expected, Kramdown::Document.new(text).to_html)
- end
+ assert_equal(expected, actual)
+ end
end
diff --git a/test/test_option_error.rb b/test/test_option_error.rb
index c91dc9f..8de4ee8 100644
--- a/test/test_option_error.rb
+++ b/test/test_option_error.rb
@@ -3,7 +3,7 @@
require 'test_helper'
class TestOptionError < Minitest::Test
- BASE_HTML = "h1
"
+ BASE_HTML = 'h1
'
EXPECTED_HTML = <<-HTML
- h1
@@ -18,14 +18,14 @@ def test_option_is_nil
end
def test_option_is_epmty_string
- parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, "")
+ 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")
+ 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)
diff --git a/test/test_various_toc_html.rb b/test/test_various_toc_html.rb
index 3c1c1d1..44fe7fc 100644
--- a/test/test_various_toc_html.rb
+++ b/test/test_various_toc_html.rb
@@ -44,6 +44,12 @@ class TestVariousTocHtml < Minitest::Test
no_toc h4
HTML
+ TEST_JAPANESE_HTML = <<-HTML
+あ
+い
+う
+ HTML
+
def test_nested_toc
parser = Jekyll::TableOfContents::Parser.new(TEST_HTML_1)
doc = Nokogiri::HTML(parser.toc)
@@ -177,4 +183,27 @@ def test_no_toc
assert_equal(expected, actual)
end
+
+ def test_japanese_toc
+ parser = Jekyll::TableOfContents::Parser.new(TEST_JAPANESE_HTML)
+ doc = Nokogiri::HTML(parser.toc)
+ expected = <<-HTML
+
+ HTML
+ actual = doc.css('ul.section-nav').to_s
+
+ assert_equal(expected, actual)
+ end
end