@@ -96,16 +96,25 @@ constexpr std::array kDisallowsParagraphEndTagOmissionWhenClosed{
} // namespace
void Parser::on_token(html2::Tokenizer &, html2::Token &&token) {
static constexpr auto kHandledByOldParser = [](html2::InsertionMode const &mode) {
return std::holds_alternative<html2::InBody>(mode) || std::holds_alternative<html2::AfterHead>(mode);
};
// Everything in <head> and earlier is handled by the new parser.
if (!std::holds_alternative<html2::AfterHead>(insertion_mode_)) {
if (!kHandledByOldParser(insertion_mode_)) {
insertion_mode_ = std::visit([&](auto &mode) { return mode.process(actions_, token); }, insertion_mode_)
.value_or(insertion_mode_);
if (auto const *end = std::get_if<html2::EndTagToken>(&token); end != nullptr && end->tag_name == "head") {
return;
}
if (auto const *start = std::get_if<html2::StartTagToken>(&token);
start != nullptr && start->tag_name == "body") {
return;
}
}
if (std::holds_alternative<html2::AfterHead>(insertion_mode_)) {
if (kHandledByOldParser(insertion_mode_)) {
std::visit(*this, token);
}
}