2022.1

Table Of Contents
2. Add the:notselector to the queries in the script, specifying that class. Remember to put a
dot before the name of the class. For example: merge.context.query("h1:not
(.ignore-me), h2").
Adding internal hyperlinks
It is possible to create links in a table of contents that point to the respective position in the
document (for example when generating PDF output). An internal hyperlink points to an
element with a specified ID. (See: "Hyperlink and mailto link" on page759.)
Here's how to change the each() function in the script in order to add internal hyperlinks to the
table of contents:
1. Add the following variable: var linknumber = 1;. This variable is used to generate
unique IDs for elements that don't have an ID.
2. Before the first line that starts with 'toc ', add the following:
var anchorId = '';
if (this.attr("id")) {
anchorId = this.attr("id");
}
else {
anchorId = 'generatedID-' + linknumber;
linknumber++;
this.attr("id", anchorId);
}
This code takes the element's ID. If an element doesn't have an ID, the script generates a
new, unique ID for it.
3. Replace the line:
toc += '<span class="text">' + text + '</span>';
with this line:
toc += '<a class="text" href="#' + anchorId + '">' + text +
'</a>';
The new line adds a hyperlink: <a ... href> with the element's ID to the table of contents.
Step 4: Styling the table of contents
Each component of the table of contents inserted in Step 3 is wrapped in a <span> element that
has a class, for example: "dots" or even multiple classes: "toc-entry h1". (Class names are
separated by a space.)
Page 976