diff options
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLParser.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Libraries/LibWeb/Parser/HTMLParser.cpp b/Libraries/LibWeb/Parser/HTMLParser.cpp index af945af006..7dfbfcdb10 100644 --- a/Libraries/LibWeb/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLParser.cpp @@ -95,6 +95,12 @@ static bool parse_html_document(const StringView& html, Document& document, Pare bool is_slash_tag = false; bool is_exclamation_tag = false; + auto commit_text_node = [&] { + auto text_node = adopt(*new Text(document, text_buffer.to_string())); + node_stack.last().append_child(text_node, false); + text_buffer.clear(); + }; + auto move_to_state = [&](State new_state) { if (new_state == State::BeforeTagName) { is_slash_tag = false; @@ -106,9 +112,8 @@ static bool parse_html_document(const StringView& html, Document& document, Pare attribute_name_buffer.clear(); if (new_state == State::BeforeAttributeValue) attribute_value_buffer.clear(); - if (state == State::Free && !text_buffer.string_view().is_empty()) { - auto text_node = adopt(*new Text(document, text_buffer.to_string())); - node_stack.last().append_child(text_node, false); + if (state == State::Free && !text_buffer.is_empty()) { + commit_text_node(); } state = new_state; text_buffer.clear(); @@ -348,6 +353,9 @@ static bool parse_html_document(const StringView& html, Document& document, Pare } } + if (!text_buffer.is_empty()) + commit_text_node(); + return true; } |