System.err.println("popped " + ns + " : " + name + ", node=" + node
+ " @ " + endTok.pos);
}
if (needsDebugData) {
name = Html5ElementStack.canonicalElementName(name);
FilePosition endPos;
if (startTok.type == HtmlTokenType.TAGBEGIN
// A start <select> tag inside a select element is treated as a close
// select tag. Don't ask -- there's just no good reason.
// http://www.whatwg.org/specs/web-apps/current-work/#in-select
// If the insertion mode is "in select"
// A start tag whose tag name is "select"
// Parse error. Act as if the token had been an end tag
// with the tag name "select" instead.
&& (isEndTag(startTok.text) || "select".equals(name))
&& tagCloses(tagName(startTok.text), name)) {
endPos = endTok.pos;
} else {
// Implied ending.
endPos = FilePosition.startOf(startTok.pos);
}
FilePosition startPos = Nodes.getFilePositionFor(node);
if (startPos.source().equals(InputSource.UNKNOWN)) {
Node first = node.getFirstChild();
if (first != null) {
startPos = Nodes.getFilePositionFor(first);
}
}
FilePosition lastPos = startPos;
Node last;
for (last = node.getLastChild(); last != null;
last = last.getPreviousSibling()) {
if (last.getNodeType() != Node.TEXT_NODE
|| !isWhitespace(last.getNodeValue())) {
break;
}
}
if (last != null) {
lastPos = Nodes.getFilePositionFor(last);
}
if (DEBUG) {
System.err.println("startPos=" + startPos + ", lastPos=" + lastPos
+ ", removed=" + removed);
}
if (endPos.endCharInFile() >= lastPos.endCharInFile()
&& (removed || lastPos.endCharInFile() > startPos.endCharInFile())) {
Nodes.setFilePositionFor(node, FilePosition.span(startPos, endPos));
}
}
}