mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +00:00
LibWeb/CSS: Don't serialize empty rules in CSSMediaRule
This is a recent spec change: https://github.com/w3c/csswg-drafts/pull/10981
This commit is contained in:
parent
0522e514a9
commit
8003d63ff9
Notes:
github-actions[bot]
2024-10-14 08:51:42 +00:00
Author: https://github.com/ronak69
Commit: 8003d63ff9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1701
Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 12 additions and 10 deletions
|
@ -54,21 +54,23 @@ String CSSMediaRule::serialized() const
|
|||
builder.append(condition_text());
|
||||
// 3. A single SPACE (U+0020), followed by the string "{", i.e., LEFT CURLY BRACKET (U+007B), followed by a newline.
|
||||
builder.append(" {\n"sv);
|
||||
// AD-HOC: All modern browsers omit the ending newline if there are no CSS rules, so let's do the same.
|
||||
if (css_rules().length() == 0) {
|
||||
builder.append('}');
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
// 4. The result of performing serialize a CSS rule on each rule in the rule’s cssRules list, separated by a newline and indented by two spaces.
|
||||
// 4. The result of performing serialize a CSS rule on each rule in the rule’s cssRules list,
|
||||
// filtering out empty strings, indenting each item with two spaces, all joined with newline.
|
||||
for (size_t i = 0; i < css_rules().length(); i++) {
|
||||
auto rule = css_rules().item(i);
|
||||
if (i != 0)
|
||||
builder.append("\n"sv);
|
||||
auto result = rule->css_text();
|
||||
|
||||
if (result.is_empty())
|
||||
continue;
|
||||
|
||||
builder.append(" "sv);
|
||||
builder.append(rule->css_text());
|
||||
builder.append(result);
|
||||
builder.append('\n');
|
||||
}
|
||||
// 5. A newline, followed by the string "}", i.e., RIGHT CURLY BRACKET (U+007D)
|
||||
builder.append("\n}"sv);
|
||||
// AD-HOC: All modern browsers omit the ending newline if there are no CSS rules, so let's do the same.
|
||||
// If there are rules, the required newline will be appended in the for-loop above.
|
||||
builder.append('}');
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue