#include <iostream>
int main(int argc, char* argv[]) {
g {
fill: black;
}
path {
fill: blue;
}
path.withColor {
fill: red !important;
stroke: blue;
}
g > :nth-child(2n of path) {
fill: green;
}
)");
std::cout << "Parsed stylesheet:\n" << stylesheet << "\n";
std::cout << "Using document tree:\n";
for (
const auto& rule : stylesheet.
rules()) {
bool foundMatch = false;
std::cout << "Matching " << rule.selector << ":\n";
for (const auto& element : {group, path1, path2}) {
foundMatch = true;
std::cout << " - Matched " << element << " - " << match.specificity << "\n";
}
}
if (foundMatch) {
std::cout << "\n";
} else {
std::cout << " - No match\n\n";
}
}
std::cout << "Parsed selector: " << *selector << "\n";
std::cout << "Matched " << path1 << " - " << match.specificity << "\n";
} else {
std::cout << "No match\n";
}
} else {
std::cerr << "Failed to parse selector\n";
std::abort();
}
std::cout << "Parsed style attribute:\n";
for (const auto& declaration : declarations) {
std::cout << declaration << "\n";
}
return 0;
}
A test fake for a type that satisfies the ElementLike concept.
Definition FakeElement.h:23
void appendChild(const FakeElement &child)
Appends a new child to this element's child list.
Definition FakeElement.h:188
void setClassName(const RcString &className)
Sets the element class name, the value of the "class" attribute.
Definition FakeElement.h:179
void setAttribute(const xml::XMLQualifiedNameRef &name, const RcString &value)
Sets the value of an attribute.
Definition FakeElement.h:182
DeferredPrinter printAsTree() const
When used in an ostream output stream, prints the element's and all children instead of just the elem...
Definition FakeElement.h:247
void setId(const RcString &id)
Sets the element id, the value of the "id" attribute.
Definition FakeElement.h:176
A test fake for a type that satisfies the ElementLike concept.
Definition FakeElement.h:23
static Stylesheet ParseStylesheet(std::string_view str)
Parse a CSS stylesheet into a list of selectors and their associated declarations,...
Definition CSS.cc:9
static std::optional< Selector > ParseSelector(std::string_view str)
Parse a CSS selector string into a Selector object, which can be used to implement querySelector and ...
Definition CSS.cc:17
static std::vector< Declaration > ParseStyleAttribute(std::string_view str)
Parse a style="" attribute into a list of Declaration.
Definition CSS.cc:13
A CSS stylesheet, which is a list of rules.
Definition Stylesheet.h:48
std::span< const SelectorRule > rules() const
Get the list of rules in this stylesheet.
Definition Stylesheet.h:77
Donner CSS library, a standalone composable CSS parser.
Returned by Selector::matches to indicate whether the selector matched, and if so,...
Definition ComplexSelector.h:29