1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

LibWeb: Add an optional pointer to an HTMLParser to the HTMLTokenizer

This is needed to access the 'adjusted current node' in the 'Markup
declaration open state'. We don't want to create a full parser for
something like syntax highlighting, so it's optional (null) by default.
This commit is contained in:
Linus Groh 2022-02-15 18:45:10 +00:00 committed by Andreas Kling
parent 9130ecfd5e
commit 3f7086f91a
2 changed files with 6 additions and 0 deletions

View file

@ -130,6 +130,7 @@ HTMLParser::HTMLParser(DOM::Document& document, StringView input, const String&
: m_tokenizer(input, encoding) : m_tokenizer(input, encoding)
, m_document(document) , m_document(document)
{ {
m_tokenizer.set_parser({}, *this);
m_document->set_should_invalidate_styles_on_attribute_changes(false); m_document->set_should_invalidate_styles_on_attribute_changes(false);
auto standardized_encoding = TextCodec::get_standardized_encoding(encoding); auto standardized_encoding = TextCodec::get_standardized_encoding(encoding);
VERIFY(standardized_encoding.has_value()); VERIFY(standardized_encoding.has_value());

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -110,6 +111,8 @@ public:
Optional<HTMLToken> next_token(); Optional<HTMLToken> next_token();
void set_parser(Badge<HTMLParser>, HTMLParser& parser) { m_parser = &parser; }
void switch_to(Badge<HTMLParser>, State new_state); void switch_to(Badge<HTMLParser>, State new_state);
void switch_to(State new_state) void switch_to(State new_state)
{ {
@ -151,6 +154,8 @@ private:
void restore_to(Utf8CodePointIterator const& new_iterator); void restore_to(Utf8CodePointIterator const& new_iterator);
HTMLToken::Position nth_last_position(size_t n = 0); HTMLToken::Position nth_last_position(size_t n = 0);
HTMLParser* m_parser { nullptr };
State m_state { State::Data }; State m_state { State::Data };
State m_return_state { State::Data }; State m_return_state { State::Data };