diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp index a318d2a895..51088e300f 100644 --- a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -34,9 +35,9 @@ #include #include -#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); diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.h b/Libraries/LibWeb/Parser/HTMLDocumentParser.h index f8cd1f28e1..f74d018876 100644 --- a/Libraries/LibWeb/Parser/HTMLDocumentParser.h +++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.h @@ -96,6 +96,7 @@ private: RefPtr insert_html_element(HTMLToken&); Element& current_node(); void insert_character(u32 data); + void insert_comment(HTMLToken&); void reconstruct_the_active_formatting_elements(); void process_using_the_rules_for(InsertionMode, HTMLToken&);