2019.2

Table Of Contents
Note that the info() function can also be used to get an element's sheet number, the section it is
located in, and the total page count and sheet count of that section (see "PaginationInfo" on
page1388 and "info()" on page1393). In this case only the page number is used.
Then the callback function adds an entry to the variable that holds the table of contents, using
the retrieved info.
toc += '<p class="toc-entry ' + level + '">';
toc += '<span class="text">' + text + '</span>';
toc += '<span class="dots"></span>';
toc += '<span class="number">' + pageNo + '</span></p>';
The HTML tag name is added as a class. This can be used in a CSS file to style the entries in
the table of contents according to their level. (See "Step 4: Styling the table of contents" on
page906.)
The empty span between the heading's text and page number has the class dots. This is used
to put dots between heading and page number.
The number class (for the page number) is not only used in CSS, but also later on in the script.
The table of contents is inserted in the section with: results.html(toc ); (see "Examples" on
page1315).
The table of contents may get too long for a single page and affect the page numbers in other
sections. In that case it is necessary to re-paginate the content; merge.section.paginate(); does
the trick.
Note
Whether page numbering restarts in each section, depends on the settings for page
numbering; see "Configuring page numbers" on page501. By default, page numbering
starts with page 1 for each section.
If the pagination process has changed the page numbers, the TOC needs to be updated as
well.
To do that, the script first has to collect the page numbers from the table of contents. This is
where the number class comes in handy: var $numbers = query('.number');.
Note that this query() function, as opposed to merge.context.query(), only searches the current
section (see "query()" on page1349).
Then, the level 1 and 2 headings are collected from all Print sections again using
Page 904