libhtmlpp 1.0.0
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
libhtmlpp Namespace Reference

Core namespace for the libhtmlpp HTML parsing and printing library. More...

Classes

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)
 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)
 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
 

Detailed Description

Core namespace for the libhtmlpp HTML parsing and printing library.

Enumeration Type Documentation

◆ ElementType

Enumerator
TextEl 
HtmlEl 
CommentEl 
ScriptEL 
SvgEL 
TextAreaEL 

Definition at line 64 of file html.h.

Function Documentation

◆ _copy()

void libhtmlpp::_copy ( libhtmlpp::Element dest,
const libhtmlpp::Element src 
)

Definition at line 1102 of file html.cpp.

◆ collectStyleBlocks()

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.

◆ getCSSRules()

libhtmlpp::CSSRuleResult libhtmlpp::getCSSRules ( HtmlElement target,
const CSSStyleSheet sheet,
std::set< std::string > &  seenMediaBlocks 
)

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.

Definition at line 116 of file htmlcss.cpp.

◆ HtmlDecode() [1/2]

void libhtmlpp::HtmlDecode ( const std::string &  input,
HtmlString output 
)

Decodes special HTML characters in a string and appends to an HtmlString.

Parameters
inputPlain input string.
outputDestination HtmlString that receives encoded characters.

Definition at line 722 of file html.cpp.

◆ HtmlDecode() [2/2]

void libhtmlpp::HtmlDecode ( const std::string &  input,
std::string &  output 
)

Decodes special HTML characters in a string and appends to an std::string.

Parameters
inputPlain input string.
outputDestination HtmlString that receives encoded characters.

Definition at line 705 of file html.cpp.

◆ HtmlEncode()

void libhtmlpp::HtmlEncode ( const std::string &  input,
std::string &  output 
)

Encodes special HTML characters in a string and writes into std::string.

Parameters
inputPlain input string.
outputReceives encoded HTML string.

Definition at line 688 of file html.cpp.

◆ isalpha()

bool libhtmlpp::isalpha ( const char  src)
inline

Definition at line 55 of file utils.h.

◆ isdigit()

bool libhtmlpp::isdigit ( const char  src)
inline

Definition at line 46 of file utils.h.

◆ print()

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).

Parameters
elementRoot element to print.
outputOutput buffer to append serialized HTML to.
formatedIf true, pretty-prints the output with line breaks/indentation.

Definition at line 2154 of file html.cpp.

◆ resolveCSSVariables()

std::string libhtmlpp::resolveCSSVariables ( const std::string &  value,
const std::map< std::string, std::string > &  customProperties 
)

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.

Definition at line 757 of file css.cpp.

◆ reverse()

void libhtmlpp::reverse ( char  s[])
inline

Definition at line 35 of file utils.h.

Variable Documentation

◆ ContainerTypes

const std::array<std::string_view,100> libhtmlpp::ContainerTypes

Definition at line 62 of file html.cpp.

◆ HtmlSigns

const char* libhtmlpp::HtmlSigns[][2]
Initial value:
={
{"\"","&quot;"},
{"&","&amp;"},
{"<","&lt;"},
{">","&gt;"},
{"'","&apos;"},
{"+","&plus;"},
{nullptr,nullptr}
}

Definition at line 31 of file encode.h.