srctree

Robin Linden parent f4602764 aeb8b97f
css: Parse and store custom properties

inlinesplit
css/parser.cpp added: 11, removed: 4, total 7
@@ -416,7 +416,9 @@ std::optional<css::Rule> Parser::parse_rule() {
}
 
auto [name, value] = *decl;
if (value.ends_with("!important")) {
if (name.starts_with("--")) {
rule.custom_properties.insert_or_assign(std::string{name}, std::string{value});
} else if (value.ends_with("!important")) {
value.remove_suffix(std::strlen("!important"));
add_declaration(rule.important_declarations, name, util::trim(value));
} else {
 
css/parser_test.cpp added: 11, removed: 4, total 7
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021 Mikael Larsson <c.mikael.larsson@gmail.com>
//
// SPDX-License-Identifier: BSD-2-Clause
@@ -1184,5 +1184,10 @@ int main() {
std::map<css::PropertyId, std::string>{});
});
 
etest::test("parser: custom property", [] {
expect_eq(css::parse("p { --var: value; }").rules.at(0), //
css::Rule{.selectors = {{"p"}}, .custom_properties = {{"--var", "value"}}});
});
 
return etest::run_all_tests();
}