Skip to content

Commit

Permalink
Update README (#127)
Browse files Browse the repository at this point in the history
* Remove features from test_files

* Modify description

* {% toc %} tag / toc_only filter

* Move "Default Configuration" to the customization section

* Add  _config.yml

* Refine English

* Add " Alternative Tools"

* Update TOC

* Update README.md

* Update TOC again

* Add "Enable TOC by default"

closes #116
  • Loading branch information
toshimaru authored Oct 25, 2020
1 parent 3f9a7f1 commit 0326e85
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@

- [Installation](#installation)
- [Usage](#usage)
- [1. Basic Usage](#1-basic-usage)
- [2. Advanced Usage](#2-advanced-usage)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Generated HTML](#generated-html)
- [Default Configuration](#default-configuration)
- [Customization](#customization)
- [Default Configuration](#default-configuration)
- [TOC levels](#toc-levels)
- [Enable TOC by default](#enable-toc-by-default)
- [Skip TOC](#skip-toc)
- [Skip TOC Section](#skip-toc-section)
- [Skip TOC Sectionally](#skip-toc-sectionally)
- [CSS Styling](#css-styling)
- [Custom CSS Class](#custom-css-class)
- [Using Unordered/Ordered lists](#using-unorderedordered-lists)
- [Alternative Tools](#alternative-tools)

## Installation

Expand Down Expand Up @@ -51,7 +53,7 @@ toc: true
There are three Liquid filters, which can be applied to HTML content,
e.g. the Liquid variable `content` available in Jekyll's templates.

### 1. Basic Usage
### Basic Usage

#### `toc` filter

Expand All @@ -63,11 +65,11 @@ Add the `toc` filter to your site's `{{ content }}` (e.g. `_layouts/post.html`).

This filter places the TOC directly above the content.

### 2. Advanced Usage
### Advanced Usage

If you'd like separated TOC and content, you can use `{% toc %}` tag (or `toc_only` filter) and `inject_anchors` filter.

#### `{% toc %}` tag
#### `{% toc %}` tag / `toc_only` filter

Generates the TOC itself as described [below](#generated-html).
Mostly useful in cases where the TOC should _not_ be placed immediately
Expand All @@ -86,7 +88,8 @@ above the content but at some other place of the page, i.e. an aside.

:warning: **`{% toc %}` Tag Limitation**

`{% toc %}` can be available only in [Jekyll Posts](https://jekyllrb.com/docs/step-by-step/08-blogging/) and [Jekyll Collections](https://jekyllrb.com/docs/collections/). If you'd like to use `{% toc %}` except posts or collections, please use `toc_only` filter as described below.
`{% toc %}` works only for [Jekyll Posts](https://jekyllrb.com/docs/step-by-step/08-blogging/) and [Jekyll Collections](https://jekyllrb.com/docs/collections/).
If you'd like to use `{% toc %}` except posts or collections, please use `toc_only` filter as described below.

```html
<div>
Expand Down Expand Up @@ -115,7 +118,7 @@ location with the `toc_only` filter.

## Generated HTML

jekyll-toc generates an unordered list. The HTML output is as follows.
jekyll-toc generates an unordered list by default. The HTML output is as follows.

```html
<ul class="section-nav">
Expand All @@ -141,9 +144,14 @@ jekyll-toc generates an unordered list. The HTML output is as follows.

![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)

## Default Configuration
## Customization

jekyll-toc is customizable on `_config.yml`.

### Default Configuration

```yml
# _config.yml
toc:
min_level: 1
max_level: 6
Expand All @@ -155,39 +163,49 @@ toc:
item_prefix: toc-
```

## Customization

### TOC levels

The toc levels can be configured on `_config.yml`:

```yml
# _config.yml
toc:
min_level: 2 # default: 1
max_level: 5 # default: 6
```

The default level range is `<h1>` to `<h6>`.
The default heading range is from `<h1>` to `<h6>`.

### Enable TOC by default

You can enable TOC by default with [Front Matter Defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/):

```yml
# _config.yml
defaults:
- scope:
path: ""
values:
toc: true
```

### Skip TOC

The heading is ignored in the toc when you add `no_toc` to the class.
The heading is ignored in the toc by adding `no_toc` class.

```html
<h1>h1</h1>
<h1 class="no_toc">This heading is ignored in the toc</h1>
<h1 class="no_toc">This heading is ignored in the TOC</h1>
<h2>h2</h2>
```

### Skip TOC Section
### Skip TOC Sectionally

The headings are ignored inside the element which has `no_toc_section` class.

```html
<h1>h1</h1>
<div class="no_toc_section">
<h2>This heading is ignored in the toc</h2>
<h3>This heading is ignored in the toc</h3>
<h2>This heading is ignored in the TOC</h2>
<h3>This heading is ignored in the TOC</h3>
</div>
<h4>h4</h4>
```
Expand All @@ -197,13 +215,15 @@ Which would result in only the `<h1>` & `<h4>` within the example being included
The class can be configured on `_config.yml`:

```yml
# _config.yml
toc:
no_toc_section_class: exclude # default: no_toc_section
```

Configuring multiple classes for `no_toc_section_class` is allowed:
Configuring multiple classes are allowed:

```yml
# _config.yml
toc:
no_toc_section_class:
- no_toc_section
Expand All @@ -229,14 +249,15 @@ The toc can be modified with CSS. The sample CSS is the following.

Each TOC `li` entry has two CSS classes for further styling. The general `toc-entry` is applied to all `li` elements in the `ul.section-nav`.

Depending on the heading level each specific entry refers to, it has a second CSS class `toc-XX`, where `XX` is the HTML heading tag name. For example, the TOC entry linking to a heading `<h1>...</h1>` (a single
`#` in Markdown) will get the CSS class `toc-h1`.
Depending on the heading level each specific entry refers to, it has a second CSS class `toc-XX`, where `XX` is the HTML heading tag name.
For example, the TOC entry linking to a heading `<h1>...</h1>` (a single `#` in Markdown) will get the CSS class `toc-h1`.

### Custom CSS Class

You can apply custom CSS classes to the generated `<ul>` and `<li>` tags.

```yml
# _config.yml
toc:
# Default is "section-nav":
list_class: my-list-class
Expand All @@ -254,6 +275,7 @@ By default the table of contents will be generated as an unordered list via `<ul
This can be configured in `_config.yml`:

```yml
# _config.yml
toc:
ordered_list: true # default is false
```
Expand All @@ -264,6 +286,7 @@ Add a class to the `sublist_class` configuration to append it to the `ol` tags s
Example

```yml
# _config.yml
toc:
ordered_list: true
list_class: my-list-class
Expand All @@ -283,3 +306,10 @@ toc:
This will produce:

![screenshot](https://user-images.githubusercontent.com/7675276/85813980-a0ea5a80-b719-11ea-9458-ccf9b86a778b.png)

## Alternative Tools

- Adding anchor to headings
- [AnchorJS](https://www.bryanbraun.com/anchorjs/)
- Generating TOC for kramdown content
- [Automatic “Table of Contents” Generation](https://kramdown.gettalong.org/converter/html.html#toc) (See also. [Create Table of Contents in kramdown](https://blog.toshima.ru/2020/05/22/kramdown-toc))
4 changes: 2 additions & 2 deletions jekyll-toc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Gem::Specification.new do |spec|
spec.name = 'jekyll-toc'
spec.version = Jekyll::TableOfContents::VERSION
spec.summary = 'Jekyll Table of Contents plugin'
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a table of contents.'
spec.description = 'Jekyll (Ruby static website generator) plugin which generates a Table of Contents for the page.'
spec.authors = %w(toshimaru torbjoernk)
spec.email = '[email protected]'
spec.files = `git ls-files -z`.split("\x0")
spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
spec.license = 'MIT'
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.test_files = spec.files.grep(%r{^(test|spec)/})
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.4'
Expand Down

0 comments on commit 0326e85

Please sign in to comment.