processEndTag method

  1. @override
Token? processEndTag(
  1. EndTagToken token
)
override

Implementation

@override
Token? processEndTag(EndTagToken token) {
  var nodeIndex = tree.openElements.length - 1;
  var node = tree.openElements.last;
  if (node.localName?.toAsciiLowerCase() != token.name) {
    parser.parseError(token.span, 'unexpected-end-tag', {'name': token.name});
  }

  Token? newToken;
  while (true) {
    if (node.localName?.toAsciiLowerCase() == token.name) {
      //XXX this isn't in the spec but it seems necessary
      if (parser.phase == parser._inTableTextPhase) {
        final inTableText = parser.phase as InTableTextPhase;
        inTableText.flushCharacters();
        parser.phase = inTableText.originalPhase!;
      }
      while (tree.openElements.removeLast() != node) {
        assert(tree.openElements.isNotEmpty);
      }
      newToken = null;
      break;
    }
    nodeIndex -= 1;

    node = tree.openElements[nodeIndex];
    if (node.namespaceUri != tree.defaultNamespace) {
      continue;
    } else {
      newToken = parser.phase.processEndTag(token);
      break;
    }
  }
  return newToken;
}