summaryrefslogtreecommitdiff
path: root/docs/modules/api/pages/generate-html-toc.adoc
blob: c53a538bd2a147c202d4bc3e812cbe8fc8df74f2 (plain) (blame)
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
= Generate an HTML TOC

Asciidoctor's HTML 5 converter has built-in support for generating a TOC.
This TOC generator can also be used as a general purpose API.
This logic is available via the `outline` method on the HTML5 converter.

The `outline` method excepts a Document object and an optional Hash of options, and returns an HTML string.
It can be resolved and invoked from anywhere using the following:

[source,ruby]
----
html_toc = (Asciidoctor::Converter.for 'html5').outline document
----

The method can also be executed from inside a converter template (e.g., Slim, Haml, or ERB).
When using a composite converter, this call will be run through the converter chain.

[source,ruby]
----
= converter.convert document, 'outline'
----

The method is also available through the Document API:

[source,ruby]
----
html_doc = document.converter.convert document, 'outline'
----

The `outline` method accepts the following options:

sectnumlevels:: the number of section levels to number (defaults to the value of the `sectnumlevels` attribute.
toclevels:: the depth of the toc (defaults to the value of the `toclevels` attribute)