Documark Table of Contents
Documark plugin for generating a table of contents.
This plugin uses wkhtmltopdf its --dump-outline
flag to generate the chapter index,
which means that the table of contents is always one compilation behind.
Compiling twice will ensure you have the latest table of contents.
Usage
-
Install plugin with
npm install dmp-table-of-contents --save
. -
Load plugin in document configuration:
plugins:- dmp-table-of-contents -
Add the table of contents in
document.jade
:chapter.no-indexh1 Indextable-of-contents(depth=2)The index element (
ul
) will be automatically appended to thetable-of-contents
element.Tip: Use the chapter numbering plugin for automatic chapter numbering.
-
Additionally add a
.no-index
class to headers (or one of their parent elements) to skip the index:chapterh1.no-index This will not appear in the TOC!//- Or:chapter.no-indexh1 Oneh2 Twoh3 Three
Configuration
The index depth (default: 3) can be configured with a depth
attribute:
table-of-contents(depth=2)
Use startPageCountOn
in your document configuration to shift the displayed page numbers:
startPageCountOn: 2 # to make 1 => 2, 5 => 6, 6 => 7, etc. startPageCountOn: -3 # to make 1 => -3, 5 => 1, 6 => 2, etc.
Output
The final structure will look like this:
chapter.no-index h1 Index table-of-contents(depth=2) ul.index-1 li.page-1 a.chapter-link(href='#chapter-1-subject-x') span.chapter-title 1. Subject X span.page-number 1 li.page-2 a.chapter-link(href='#chapter-2-subject-y') span.chapter-title 2. Subject Y span.page-number 2 ul.index-2 li.page-2 a.chapter-link(href='#chapter-2-1-subject-z') span.chapter-title 2.1. Subject Z span.page-number 2
Note: Chapter anchors are the slugified title, prepended with chapter-
and appended with -2
, -3
, etc. (if necessary).