LibHTML: Only accumulate Text children's content in inline stylesheets

Some inline stylesheets use HTML comments like "<!--blah blah-->".
The HTML parser currently generates a comment child node of the <style>
element whenever this happens, and we don't want the comment itself to
be interpreted as part of the stylesheet.
This commit is contained in:
Andreas Kling 2019-10-17 23:54:27 +02:00
parent 9ac7b6fad1
commit 6202a0ab32
Notes: sideshowbarker 2024-07-19 11:39:21 +09:00

View file

@ -1,5 +1,7 @@
#include <AK/StringBuilder.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/HTMLStyleElement.h>
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Parser/CSSParser.h>
HTMLStyleElement::HTMLStyleElement(Document& document, const String& tag_name)
@ -13,7 +15,12 @@ HTMLStyleElement::~HTMLStyleElement()
void HTMLStyleElement::inserted_into(Node& new_parent)
{
m_stylesheet = parse_css(text_content());
StringBuilder builder;
for_each_child([&](auto& child) {
if (is<Text>(child))
builder.append(to<Text>(child).text_content());
});
m_stylesheet = parse_css(builder.to_string());
if (m_stylesheet)
document().add_sheet(*m_stylesheet);
HTMLElement::inserted_into(new_parent);