2018.2

Table Of Contents
The following script loads a snippet. Then it looks for a placeholder (@var2@) in the text of that
snippet and replaces every found placeholder by the text '<i>OL Connect 1</i>'. It uses html()
so the HTML formatting (<i> and </i>) will indeed be interpreted as HTML. Finally, it places the
snippet in the template.
var mysnippet = loadhtml('snippets/snippet.html');
mysnippet.find('@var1@').html('<i>OL Connect 1</i>');
results.replaceWith(mysnippet);
pageRef()
Returns a marker that will be replaced with the element's page number after pagination. This
only works for elements in the section that is currently being merged.
Example
Creating a table of contents
The following script creates a table of contents for all level 1 headings (<h1> elements) with the
class title in one section.
var toc = '<ul ID="toc">';
query('h1.title').each(function()
{toc += '<li>' + this.text() + ' <span class="li_toc">' +
this.pageref() + '</span></li>';
});
toc += '</ul>';
results.after(toc);
The first line creates a variable for the table of contents, which will be a list (a <ul> element with
the ID toc). The start tag of the list is added to the variable.
The next line does a query for all level 1 headings (<h1> elements) with the class title in the
current section. With each() the script loops through them. For each of the headings it adds a
line item to the list, with the text (this.text()) and the page reference of the respective
heading.
After the loop, the end tag of the list is added to the variable.
Finally, the script adds the variable - that now contains the table of contents - after the results.
The results object contains the elements that match the selector of the script. So, if the script's
selector selects the title of the table of contents, the table of contents will be added after that.
Page 1128