mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb/CSS: Preserve whitespace and comments in custom properties
A couple of parts of this: - Store the source text for Declarations of custom properties. - Then save that in the UnresolvedStyleValue. - Serialize UnresolvedStyleValue using the saved source when available - that is, for custom properties but not for regular properties that include var() or attr().
This commit is contained in:
parent
f8995d37a2
commit
bf3e6daedb
Notes:
github-actions[bot]
2024-10-16 12:23:36 +00:00
Author: https://github.com/AtkinsSJ
Commit: bf3e6daedb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1795
4 changed files with 20 additions and 9 deletions
|
@ -953,7 +953,13 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& input, Neste
|
|||
// 8. If decl’s name is a custom property name string, then set decl’s original text to the segment
|
||||
// of the original source text string corresponding to the tokens of decl’s value.
|
||||
if (is_a_custom_property_name_string(declaration.name)) {
|
||||
// FIXME: Set the original source text
|
||||
// TODO: If we could reach inside the source string that the TokenStream uses, we could grab this as
|
||||
// a single substring instead of having to reconstruct it.
|
||||
StringBuilder original_text;
|
||||
for (auto const& value : declaration.value) {
|
||||
original_text.append(value.original_source_text());
|
||||
}
|
||||
declaration.original_text = original_text.to_string_without_validation();
|
||||
}
|
||||
// Otherwise, if decl’s value contains a top-level simple block with an associated token of <{-token>,
|
||||
// and also contains any other non-<whitespace-token> value, return nothing.
|
||||
|
@ -1738,7 +1744,7 @@ Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& dec
|
|||
}
|
||||
|
||||
auto value_token_stream = TokenStream(declaration.value);
|
||||
auto value = parse_css_value(property_id.value(), value_token_stream);
|
||||
auto value = parse_css_value(property_id.value(), value_token_stream, declaration.original_text);
|
||||
if (value.is_error()) {
|
||||
if (value.error() == ParseError::SyntaxError) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "Unable to parse value for CSS property '{}'.", property_name);
|
||||
|
@ -7636,7 +7642,7 @@ bool block_contains_var_or_attr(SimpleBlock const& block)
|
|||
return false;
|
||||
}
|
||||
|
||||
Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue>> Parser::parse_css_value(PropertyID property_id, TokenStream<ComponentValue>& unprocessed_tokens)
|
||||
Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue>> Parser::parse_css_value(PropertyID property_id, TokenStream<ComponentValue>& unprocessed_tokens, Optional<String> original_source_text)
|
||||
{
|
||||
m_context.set_current_property_id(property_id);
|
||||
Vector<ComponentValue> component_values;
|
||||
|
@ -7670,7 +7676,7 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue>> Parser::parse_css_value(Prope
|
|||
}
|
||||
|
||||
if (property_id == PropertyID::Custom || contains_var_or_attr)
|
||||
return UnresolvedStyleValue::create(move(component_values), contains_var_or_attr);
|
||||
return UnresolvedStyleValue::create(move(component_values), contains_var_or_attr, original_source_text);
|
||||
|
||||
if (component_values.is_empty())
|
||||
return ParseError::SyntaxError;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue