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 - %() + %() 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) + toc_list << %(\n\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) - 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