getNextToken method

Token getNextToken(
  1. String rawHtml
)

Implementation

Token getNextToken(String rawHtml) {
  if (rawHtml.isEmpty) {
    throw EOFException();
  }

  RegExpMatch? nextTagMatch = RegExProvider.tagRegex.firstMatch(rawHtml);

  // if there is no tag or the tag is not at the start of the string, return
  // the plaintext
  if (nextTagMatch == null || nextTagMatch.start > 0) {
    return Token(
      TokenType.plain,
      nextTagMatch == null
          ? rawHtml
          : rawHtml.substring(0, nextTagMatch.start),
    );
  }

  var tag = Tag.decodeTag(
    rawHtml.substring(nextTagMatch.start, nextTagMatch.end),
  );

  return Token(
    tag.isStart ? TokenType.start : TokenType.end,
    tag.rawTag,
  );
}