summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 936851af0448f1637a44f31e7c12b34d095e13a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# mdbook-toc

A preprocessor for [mdbook][] to add inline Table of Contents support.

[mdbook]: https://github.com/rust-lang-nursery/mdBook

It turns this marker:

```md
<!-- toc -->
```

into a Table of Contents based on headings of the chapter following the marker.

## Installation

If you want to use only this preprocessor, install the tool:

```sh
cargo install mdbook-toc
```

Add it as a preprocessor to your `book.toml`:

```toml
[preprocessor.toc]
command = "mdbook-toc"
renderer = ["html"]
```

Finally, build your book as normal:

```sh
mdbook path/to/book
```

## Configuration

### Custom TOC marker

The default marker is:

```md
<!-- toc -->
```

If you wish to use a different marker, such as the GitLab marker `[[_TOC_]]`, you must add the following settings to your `book.toml`.

```toml
[preprocessor.toc]
marker = "[[_TOC_]]"
```

You can also use multi-line markers such as the GitHub marker, which is:

```md
* auto-gen TOC;
{:toc}
```

Configure the string with a newline:

```toml
[preprocessor.toc]
marker = "* auto-gen TOC;\n{:toc}"
```

or with multi-line strings:

```toml
[preprocessor.toc]
marker = """* auto-gen TOC;
{:toc}"""
```

### Maximum header level

By default the ToC will include headings up to level 4 (`####`).
This can be configured in your `book.toml` as follows:

```toml
[preprocessor.toc]
max-level = 4
```

## License

MPL. See [LICENSE](LICENSE).  
Copyright (c) 2018-2020 Jan-Erik Rediger <janerik@fnordig.de>