|
libhtmlpp 1.0.0
|
Core namespace for the libhtmlpp HTML parsing and printing library. More...
Classes | |
| struct | AncestorFrame |
One ancestor of the element being matched, for the optional ancestor chain approximateSelectorMatch/collectApproximateMatches/getCSSRules accept – classes pre-split (whitespace-separated tokens of the ancestor's own class attribute), same shape callers already need to build for the target element. More... | |
| struct | AttributeCondition |
| One "[name]"/"[name=value]"/"[name~=value]"/etc. More... | |
| class | CommentElement |
| Leaf node representing an HTML comment (). More... | |
| class | CSSDeclaration |
| class | CSSProperty |
| class | CSSRule |
| struct | CSSRuleResult |
| Result of getCSSRules: the fully cascaded property set (name -> value, "!important" stripped) and the accumulated raw text of every matching @media (or other at-rule) block. More... | |
| class | CSSStyleSheet |
| class | DocElements |
| class | Element |
| Abstract base class for all nodes in the HTML tree. More... | |
| class | HtmlElement |
| class | HTMLException |
| class | HtmlPage |
| High level loader/saver for HTML documents (files and strings). More... | |
| class | HtmlString |
| class | HtmlTable |
| class | ScriptElement |
| Element representing a <script> tag and its text content. More... | |
| class | SvgElement |
| Element representing an embedded <svg> tag and its attributes/content. More... | |
| class | TextArea |
| Element representing an embedded <textarea> tag and its attributes/content. More... | |
| class | TextElement |
| Leaf node representing plain text content of an HTML document. More... | |
Enumerations | |
| enum | ElementType { TextEl =0 , HtmlEl =1 , CommentEl =2 , ScriptEL =3 , SvgEL =4 , TextAreaEL =5 } |
Functions | |
| std::string | resolveCSSVariables (const std::string &value, const std::map< std::string, std::string > &customProperties, bool *unresolved=nullptr) |
Resolves every var(--name) / var(--name, fallback) reference in value using customProperties (custom-property name -> its own raw stored value, e.g. | |
| void | _copy (libhtmlpp::Element *dest, const libhtmlpp::Element *src) |
| void | print (const Element &element, HtmlString &output, bool formated=false) |
| Serializes an element (and its subtree) into an HtmlString. | |
| void | HtmlDecode (const std::string &input, HtmlString &output) |
| Decodes special HTML characters in a string and appends to an HtmlString. | |
| void | HtmlDecode (const std::string &input, std::string &output) |
| Decodes special HTML characters in a string and appends to an std::string. | |
| void | HtmlEncode (const std::string &input, std::string &output) |
| Encodes special HTML characters in a string and writes into std::string. | |
| void | collectStyleBlocks (CSSStyleSheet &sheet, Element &root) |
Finds every <style> element anywhere in the subtree rooted at root (document order) and appends each one's parsed rules to sheet. | |
| CSSRuleResult | getCSSRules (HtmlElement &target, const CSSStyleSheet &sheet, std::set< std::string > &seenMediaBlocks, const std::vector< AncestorFrame > *ancestors=nullptr) |
Returns every CSS rule that applies to target: its own inline style="..." attribute, folded together with every rule in sheet whose selector CSSStyleSheet::approximateSelectorMatch's-es target's tag/class/id (see that method's doc comment for exactly what selector syntax is and isn't supported), under the same approximate-cascade rules as CSSStyleSheet::collectApproximateMatches (inline > !important > later-rule-wins). | |
| void | reverse (char s[]) |
| bool | isdigit (const char src) |
| bool | isalpha (const char src) |
Variables | |
| const char * | HtmlSigns [][2] |
| const std::array< std::string_view, 100 > | ContainerTypes |
Core namespace for the libhtmlpp HTML parsing and printing library.
| void libhtmlpp::_copy | ( | libhtmlpp::Element * | dest, |
| const libhtmlpp::Element * | src | ||
| ) |
| void libhtmlpp::collectStyleBlocks | ( | CSSStyleSheet & | sheet, |
| Element & | root | ||
| ) |
Finds every <style> element anywhere in the subtree rooted at root (document order) and appends each one's parsed rules to sheet.
Does not clear sheet first – call CSSStyleSheet::clear() beforehand for a standalone result, or rely on this to add to whatever sheet already holds (e.g. rules from an externally fetched/loaded stylesheet the caller appended separately, in whichever document order the caller's own sources warrant – this library does no network or file I/O of its own, so combining <style> blocks with any other CSS source in the right relative order is the caller's responsibility).
Definition at line 67 of file htmlcss.cpp.
| libhtmlpp::CSSRuleResult libhtmlpp::getCSSRules | ( | HtmlElement & | target, |
| const CSSStyleSheet & | sheet, | ||
| std::set< std::string > & | seenMediaBlocks, | ||
| const std::vector< AncestorFrame > * | ancestors = nullptr |
||
| ) |
Returns every CSS rule that applies to target: its own inline style="..." attribute, folded together with every rule in sheet whose selector CSSStyleSheet::approximateSelectorMatch's-es target's tag/class/id (see that method's doc comment for exactly what selector syntax is and isn't supported), under the same approximate-cascade rules as CSSStyleSheet::collectApproximateMatches (inline > !important > later-rule-wins).
sheet is expected to already contain every CSS source that should apply – e.g. built via collectStyleBlocks(sheet, documentRoot) plus any externally fetched/ loaded stylesheet's rules the caller appended itself, in real document order – this function does not fetch or load anything on its own. seenMediaBlocks is caller-owned so it can be shared across many calls (e.g. one per element while walking a whole document) to avoid accumulating the exact same @media block's text once per matching element – see CSSStyleSheet::collectApproximateMatches. ancestors is forwarded to CSSStyleSheet::collectApproximateMatches exactly as described there: nullptr (the default) means no ancestor/combinator verification (this function's original behavior), a non-null chain (see AncestorFrame) makes a descendant selector's leading compounds required to actually be found among target's ancestors, in order, instead of being ignored. target's own attribute map (built here from its actual attributes, no extra parameter needed) is forwarded as CSSStyleSheet::collectApproximateMatches's targetAttributes, so an attribute-selector condition on the TARGET compound itself (e.g. ".fade-box[data-fit=fill]") is verified instead of ignored – unlike an ancestor's attributes, target's are always available here.
Definition at line 116 of file htmlcss.cpp.
| void libhtmlpp::HtmlDecode | ( | const std::string & | input, |
| HtmlString & | output | ||
| ) |
Decodes special HTML characters in a string and appends to an HtmlString.
| input | Plain input string. |
| output | Destination HtmlString that receives encoded characters. |
| void libhtmlpp::HtmlDecode | ( | const std::string & | input, |
| std::string & | output | ||
| ) |
Decodes special HTML characters in a string and appends to an std::string.
| input | Plain input string. |
| output | Destination HtmlString that receives encoded characters. |
| void libhtmlpp::HtmlEncode | ( | const std::string & | input, |
| std::string & | output | ||
| ) |
| void libhtmlpp::print | ( | const Element & | element, |
| HtmlString & | output, | ||
| bool | formated = false |
||
| ) |
Serializes an element (and its subtree) into an HtmlString.
Serializes an element (and its subtree) into an HtmlString (definition).
| element | Root element to print. |
| output | Output buffer to append serialized HTML to. |
| formated | If true, pretty-prints the output with line breaks/indentation. |
| std::string libhtmlpp::resolveCSSVariables | ( | const std::string & | value, |
| const std::map< std::string, std::string > & | customProperties, | ||
| bool * | unresolved = nullptr |
||
| ) |
Resolves every var(--name) / var(--name, fallback) reference in value using customProperties (custom-property name -> its own raw stored value, e.g.
from parsing "--color-bg: 0,0,0;"), recursively – a custom property's own stored value may itself reference other custom properties (e.g. "--gradient-bg:
var(--something)") – with cycle detection: a reference cycle is invalid per the CSS Custom Properties spec, and resolves to "" rather than looping forever. A referenced name that's both absent from customProperties and has no fallback also resolves to "" (invalid, matching spec behavior for an unresolvable var()). A value containing no "var(" at all is returned unchanged (the overwhelmingly common case). This is pure text substitution – the stored value of a custom property is inserted verbatim at the var(...) call's position, exactly as a browser's cascade would; no CSS value-type awareness (color/length/etc.) is needed or applied.
If unresolved is non-null, it's set to true when any var() reference turned out invalid (cyclic, or absent with no fallback) – i.e. when the "" substitution happened at least once. A caller that needs real CSS semantics (an invalid var() invalidates the whole declaration, not just that one reference) should drop the property entirely in that case instead of keeping this partially-substituted text, since e.g. calc(var(--missing) * 1px) resolving to calc( * 1px) is syntactically broken rather than cleanly absent.
| const std::array<std::string_view,100> libhtmlpp::ContainerTypes |