mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
LibWeb/CSS: Move "serialize a CSS declaration" to Serialize.{h,cpp}
We need this in other places, so make it available for reuse. Also, update step 4 which now only appends `value` if it contains non-whitespace.
This commit is contained in:
parent
a2c89f585f
commit
2b67cb5f98
Notes:
github-actions[bot]
2025-03-27 11:54:13 +00:00
Author: https://github.com/AtkinsSJ
Commit: 2b67cb5f98
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4106
3 changed files with 33 additions and 51 deletions
|
@ -223,4 +223,32 @@ String serialize_a_srgb_value(Color color)
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-declaration
|
||||
String serialize_a_css_declaration(StringView property, StringView value, Important important)
|
||||
{
|
||||
// 1. Let s be the empty string.
|
||||
StringBuilder builder;
|
||||
|
||||
// 2. Append property to s.
|
||||
builder.append(property);
|
||||
|
||||
// 3. Append ": " (U+003A U+0020) to s.
|
||||
builder.append(": "sv);
|
||||
|
||||
// 4. If value contains any non-whitespace characters, append value to s.
|
||||
if (!value.is_whitespace())
|
||||
builder.append(value);
|
||||
|
||||
// 5. If the important flag is set, append " !important" (U+0020 U+0021 U+0069 U+006D U+0070 U+006F U+0072 U+0074
|
||||
// U+0061 U+006E U+0074) to s.
|
||||
if (important == Important::Yes)
|
||||
builder.append(" !important"sv);
|
||||
|
||||
// 6. Append ";" (U+003B) to s.
|
||||
builder.append(';');
|
||||
|
||||
// 7. Return s.
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue