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
Notes: sideshowbarker 2024-07-19 06:10:21 +09:00
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);

View file

@ -96,6 +96,7 @@ private:
RefPtr<Element> 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&);