1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 04:44:58 +00:00

LibWeb: Support comments in the "in head" insertion mode

This commit is contained in:
Andreas Kling 2020-05-24 20:29:01 +02:00
parent 20911efd4d
commit af8a9331b2
2 changed files with 17 additions and 3 deletions

View file

@ -25,6 +25,7 @@
*/
#include <AK/Utf32View.h>
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/ElementFactory.h>
@ -34,9 +35,9 @@
#include <LibWeb/Parser/HTMLDocumentParser.h>
#include <LibWeb/Parser/HTMLToken.h>
#define TODO() \
do { \
ASSERT_NOT_REACHED(); \
#define TODO() \
do { \
ASSERT_NOT_REACHED(); \
} while (0)
namespace Web {
@ -179,6 +180,13 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token)
ASSERT_NOT_REACHED();
}
void HTMLDocumentParser::insert_comment(HTMLToken& token)
{
auto data = token.m_comment_or_character.data.to_string();
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
adjusted_insertion_location->append_child(adopt(*new Comment(document(), data)));
}
void HTMLDocumentParser::handle_in_head(HTMLToken& token)
{
if (token.is_parser_whitespace()) {
@ -186,6 +194,11 @@ void HTMLDocumentParser::handle_in_head(HTMLToken& token)
return;
}
if (token.is_comment()) {
insert_comment(token);
return;
}
if (token.is_start_tag() && token.tag_name() == "title") {
insert_html_element(token);
m_tokenizer.switch_to({}, HTMLTokenizer::State::RCDATA);