public ITableOfContent appendHead(String rawHead, int headLevel, boolean noToC, int headCounter, int startPosition,
int endPosition) {
TagStack localStack = WikipediaParser.parseRecursive(rawHead.trim(), this, true, true);
WPTag headTagNode = new WPTag("h" + headLevel);
TagNode spanTagNode = new TagNode("span");
// Example:
// <h2><span class="mw-headline" id="Header_level_2">Header level
// 2</span></h2>
spanTagNode.addChildren(localStack.getNodeList());
headTagNode.addChild(spanTagNode);
String tocHead = headTagNode.getBodyString();
String anchor = Encoder.encodeDotUrl(tocHead);
createTableOfContent(false);
if (!noToC && (headCounter > 3)) {
fTableOfContentTag.setShowToC(true);
}
if (fToCSet.contains(anchor)) {
String newAnchor = anchor;
for (int i = 2; i < Integer.MAX_VALUE; i++) {
newAnchor = anchor + '_' + Integer.toString(i);
if (!fToCSet.contains(newAnchor)) {
break;
}
}
anchor = newAnchor;
}
fToCSet.add(anchor);
SectionHeader strPair = new SectionHeader(headLevel, startPosition, endPosition, tocHead, anchor);
addToTableOfContent(fTableOfContent, strPair, headLevel);
if (getRecursionLevel() == 1) {
buildEditLinkUrl(fSectionCounter++);
}
spanTagNode.addAttribute("class", "mw-headline", true);
spanTagNode.addAttribute("id", anchor, true);
append(headTagNode);
return fTableOfContentTag;
}