37 std::transform(t.begin(), t.end(), t.begin(),
38 [](
unsigned char c) { return std::tolower(c); });
48 size_t bang = value.rfind(
'!');
49 if (bang == std::string::npos)
return;
51 size_t start = value.find_first_not_of(
" \t\n\r", bang + 1);
52 size_t end = value.find_last_not_of(
" \t\n\r");
53 if (start == std::string::npos || end == std::string::npos || start > end)
return;
55 std::string tail = value.substr(start, end - start + 1);
56 std::transform(tail.begin(), tail.end(), tail.begin(),
57 [](
unsigned char c) { return std::tolower(c); });
58 if (tail !=
"important")
return;
61 while (valEnd > 0 && std::isspace(
static_cast<unsigned char>(value[valEnd - 1]))) --valEnd;
73 std::vector<Element*> searchStack;
74 searchStack.push_back(&root);
76 while (!searchStack.empty()) {
77 Element *cur = searchStack.back();
78 searchStack.pop_back();
80 std::vector<Element*> childFrames;
91 cssText +=
static_cast<TextElement*
>(child)->getText();
95 if (!cssText.empty()) {
97 partial.
parse(cssText);
98 for (
const auto &rule : partial.
getRules()) {
104 if (child) childFrames.push_back(child);
110 for (
auto it = childFrames.rbegin(); it != childFrames.rend(); ++it) {
111 searchStack.push_back(*it);
118 std::set<std::string> &seenMediaBlocks)
124 std::string value = prop.getValue();
const std::vector< CSSProperty > & getProperties() const
void parse(const std::string &input)
void collectApproximateMatches(const std::string &tag, const std::string &cssClass, const std::string &id, std::map< std::string, std::string > &props, std::string &mediaRules, std::set< std::string > &seenMediaBlocks) const
Runs every rule in this sheet through approximateSelectorMatch against the element identified by tag/...
const std::vector< CSSRule > & getRules() const
void addRule(const CSSRule &rule)
Abstract base class for all nodes in the HTML tree.
virtual int getType() const =0
Element * nextElement() const
const std::string getAtributte(const std::string &name) const
Element * firstChild() const
const std::string getTagname() const
Leaf node representing plain text content of an HTML document.
std::string lowerCopy(const std::string &s)
void stripImportant(std::string &value)
void collectStyleBlocks(CSSStyleSheet &sheet, Element &root)
Finds every <style> element anywhere in the subtree rooted at root (document order) and appends each ...
CSSRuleResult getCSSRules(HtmlElement &target, const CSSStyleSheet &sheet, std::set< std::string > &seenMediaBlocks)
Returns every CSS rule that applies to target: its own inline style="..." attribute,...
Result of getCSSRules: the fully cascaded property set (name -> value, "!important" stripped) and the...
std::map< std::string, std::string > properties