2022.2

Table Of Contents
1. Givealltheheadingsthatyouwanttobeignoredthesameclass(see"IDandclass"on
page172),forexampleignore-me.
2. Addthe:notselectortothequeriesinthescript,specifyingthatclass.Remembertoputadot
beforethenameoftheclass.Forexample:merge.context.query("h1:not(.ignore-
me), h2").
Adding internal hyperlinks
Itispossibletocreatelinksinatableofcontentsthatpointtotherespectivepositioninthedocument
(forexamplewhengeneratingPDFoutput).Aninternalhyperlinkpointstoanelementwithaspecified
ID.(See:"Hyperlinkandmailtolink"onpage237.)
Here'showtochangetheeach()functioninthescriptinordertoaddinternalhyperlinkstothetableof
contents:
1. Addthefollowingvariable:var linknumber = 1;.Thisvariableisusedtogenerateunique
IDsforelementsthatdon'thaveanID.
2. Beforethefirstlinethatstartswith'toc',addthefollowing:
var anchorId = '';
if (this.attr("id")) {
anchorId = this.attr("id");
}
else {
anchorId = 'generatedID-' + linknumber;
linknumber++;
this.attr("id", anchorId);
}
Thiscodetakestheelement'sID.Ifanelementdoesn'thaveanID,thescriptgeneratesanew,
uniqueIDforit.
3. Replacetheline:
toc += '<span class="text">' + text + '</span>';
withthisline:
toc += '<a class="text" href="#' + anchorId + '">' + text + '</a>';
4. Thenewlineaddsahyperlink:<a...href>withtheelement'sIDtothetableofcontents.
Step 4: Styling the table of contents
EachcomponentofthetableofcontentsinsertedinStep3iswrappedina<span>elementthathasa
class,forexample:"dots"orevenmultipleclasses:"toc-entryh1".(Classnamesareseparatedbya
space.)
Page 414