mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-05 18:52:56 +00:00
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:
parent
9ac7b6fad1
commit
6202a0ab32
Notes:
sideshowbarker
2024-07-19 11:39:21 +09:00
Author: https://github.com/awesomekling
Commit: 6202a0ab32
1 changed files with 8 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue