1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:58:10 +00:00

LibWeb: Add basic support for dynamic markup insertion

This implements basic support for dynamic markup insertion, adding
 * Document::open()
 * Document::write(Vector<String> const&)
 * Document::writeln(Vector<String> const&)
 * Document::close()

The HTMLParser is modified to make it possible to create a
script-created parser which initially only contains a HTMLTokenizer
without any data. Aditionally the HTMLParser::run method gains an
overload which does not modify the Document and does not run
HTMLParser::the_end() so that we can reenter the parser at a later time.
Furthermore all FIXMEs that consern the insertion point are implemented
wich is defined in the HTMLTokenizer. Additionally the following
member-variables of the HTMLParser are now exposed by getter funcions:
 * m_tokenizer
 * m_aborted
 * m_script_nesting_level

The HTMLTokenizer is modified so that it contains an insertion
point which keeps track of where the next input from the Document::write
functions will be inserted. The insertion point is implemented as the
charakter offset into m_decoded_input and a boolean describing if the
insertion point is defined. Functions to update, check and {re}store the
insertion point are also added.
The function HTMLTokenizer::insert_eof is added to tell a script-created
parser that document::close was called and HTMLParser::the_end() should
be called.
Lastly an explicit default constructor is added to HTMLTokenizer to
create a empty HTMLTokenizer into which data can be inserted.
This commit is contained in:
Lorenz Steinert 2022-02-19 15:58:21 +01:00 committed by Andreas Kling
parent d29d9462e9
commit db789813c9
7 changed files with 282 additions and 19 deletions

View file

@ -46,10 +46,12 @@ class HTMLParser {
public:
HTMLParser(DOM::Document&, StringView input, const String& encoding);
HTMLParser(DOM::Document&);
~HTMLParser();
static NonnullOwnPtr<HTMLParser> create_with_uncertain_encoding(DOM::Document&, const ByteBuffer& input);
void run();
void run(const AK::URL&);
DOM::Document& document();
@ -67,6 +69,12 @@ public:
static bool is_special_tag(const FlyString& tag_name, const FlyString& namespace_);
HTMLTokenizer& tokenizer() { return m_tokenizer; }
bool aborted() const { return m_aborted; }
size_t script_nesting_level() const { return m_script_nesting_level; }
private:
const char* insertion_mode_name() const;
@ -127,7 +135,6 @@ private:
void parse_generic_raw_text_element(HTMLToken&);
void increment_script_nesting_level();
void decrement_script_nesting_level();
size_t script_nesting_level() const { return m_script_nesting_level; }
void reset_the_insertion_mode_appropriately();
void adjust_mathml_attributes(HTMLToken&);