libhtmlpp 1.0.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
libhtmlpp::CSSStyleSheet Class Reference

#include <css.h>

Public Member Functions

 CSSStyleSheet ()
 
 CSSStyleSheet (const CSSStyleSheet &sheet)
 
 ~CSSStyleSheet ()
 
CSSStyleSheetoperator= (const CSSStyleSheet &sheet)
 
void parse (const std::string &input)
 
void addRule (const CSSRule &rule)
 
void removeRule (size_t index)
 
const CSSRulegetRule (size_t index) const
 
size_t getRuleCount () const
 
const std::vector< CSSRule > & getRules () const
 
std::string serialize (bool formatted=false) const
 
void clear ()
 
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/cssClass (a whitespace-separated class list)/id, folding matching declarations into props under an approximation of the real CSS cascade: a property already present in props when this is called (e.g.
 

Static Public Member Functions

static CSSDeclaration parseInlineStyle (const std::string &style)
 
static bool approximateSelectorMatch (const std::string &selector, const std::string &tag, const std::vector< std::string > &classes, const std::string &id)
 Conservative, NOT spec-complete selector match: selector (a single selector, or a comma-separated list of them – matches if ANY branch matches) is matched against a single element identified by tag/classes/id only there is no ancestor/parent context available, so any selector this can't safely evaluate without seeing more than that one element is REJECTED (returns false) rather than guessed.
 

Detailed Description

Definition at line 104 of file css.h.

Constructor & Destructor Documentation

◆ CSSStyleSheet() [1/2]

libhtmlpp::CSSStyleSheet::CSSStyleSheet ( )

Definition at line 452 of file css.cpp.

◆ CSSStyleSheet() [2/2]

libhtmlpp::CSSStyleSheet::CSSStyleSheet ( const CSSStyleSheet sheet)

Definition at line 454 of file css.cpp.

◆ ~CSSStyleSheet()

libhtmlpp::CSSStyleSheet::~CSSStyleSheet ( )

Definition at line 457 of file css.cpp.

Member Function Documentation

◆ addRule()

void libhtmlpp::CSSStyleSheet::addRule ( const CSSRule rule)

Definition at line 589 of file css.cpp.

◆ approximateSelectorMatch()

bool libhtmlpp::CSSStyleSheet::approximateSelectorMatch ( const std::string &  selector,
const std::string &  tag,
const std::vector< std::string > &  classes,
const std::string &  id 
)
static

Conservative, NOT spec-complete selector match: selector (a single selector, or a comma-separated list of them – matches if ANY branch matches) is matched against a single element identified by tag/classes/id only there is no ancestor/parent context available, so any selector this can't safely evaluate without seeing more than that one element is REJECTED (returns false) rather than guessed.

Rejected outright: attribute selectors ("[href]"), pseudo-classes and pseudo-elements (":hover", "::before"), the universal selector ("*"), and – after a combinator (space/">"/"+"/"~") is stripped down to its trailing compound selector – a bare tag left with no class/id qualifier of its own (e.g. "[data-x]>div" reduces to a bare "div", which would otherwise match every element of that tag in the whole document; a qualified compound like "div.foo" is still specific enough to check). A compound selector like "div.card.featured#hero" matches only if the tag (when given), every class listed (all of them, not just one), and the id (when given) are all present on the element. This is intentionally an approximation of real CSS selector matching, not an implementation of it – there is no specificity calculation and no combinator/ancestor verification – built to be safe against false positives on real-world scraped markup rather than complete; treat a false result as "not proven to match", not "definitely doesn't".

Definition at line 632 of file css.cpp.

◆ clear()

void libhtmlpp::CSSStyleSheet::clear ( )

Definition at line 622 of file css.cpp.

◆ collectApproximateMatches()

void libhtmlpp::CSSStyleSheet::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/cssClass (a whitespace-separated class list)/id, folding matching declarations into props under an approximation of the real CSS cascade: a property already present in props when this is called (e.g.

the element's own inline style, set by the caller before calling this) outranks a later plain rule unless that rule's value carries "!important" (stripped from the stored value either way); among this sheet's own rules, a later rule beats an earlier one at equal priority. This is "last rule of equal-or-higher precedence wins", not full CSS specificity. Each matching @media/other at-rule block's raw text is appended to mediaRules, skipped if its exact text is already present in seenMediaBlocks (both are caller-owned, so a caller processing many elements from one document/sheet can share one instance of each across all of them and avoid repeating an identical block once per matching element).

Definition at line 659 of file css.cpp.

◆ getRule()

const libhtmlpp::CSSRule * libhtmlpp::CSSStyleSheet::getRule ( size_t  index) const

Definition at line 599 of file css.cpp.

◆ getRuleCount()

size_t libhtmlpp::CSSStyleSheet::getRuleCount ( ) const

Definition at line 604 of file css.cpp.

◆ getRules()

const std::vector< libhtmlpp::CSSRule > & libhtmlpp::CSSStyleSheet::getRules ( ) const

Definition at line 608 of file css.cpp.

◆ operator=()

libhtmlpp::CSSStyleSheet & libhtmlpp::CSSStyleSheet::operator= ( const CSSStyleSheet sheet)

Definition at line 459 of file css.cpp.

◆ parse()

void libhtmlpp::CSSStyleSheet::parse ( const std::string &  input)

Definition at line 484 of file css.cpp.

◆ parseInlineStyle()

libhtmlpp::CSSDeclaration libhtmlpp::CSSStyleSheet::parseInlineStyle ( const std::string &  style)
static

Definition at line 626 of file css.cpp.

◆ removeRule()

void libhtmlpp::CSSStyleSheet::removeRule ( size_t  index)

Definition at line 593 of file css.cpp.

◆ serialize()

std::string libhtmlpp::CSSStyleSheet::serialize ( bool  formatted = false) const

Definition at line 612 of file css.cpp.


The documentation for this class was generated from the following files: