parsers::html
Functions
Escape the markup-significant characters in s (Python html.escape).
Replaces &→&, <→<, >→> always, and when quote is true (the default) also "→" and '→', so the result is safe to drop into element text and into a quoted attribute value.
s | the text to escape. |
quote | also escape the quote characters (default true). |
a newly allocated escaped copy.
O(n) time in the length of s.
one result string on the heap.
ParsersCompileRun.HtmlEscapeUnescapeResolve character references back to text (Python html.unescape).
Decodes decimal (©) and hexadecimal (©) numeric references and a table of the common named entities (&, <, >, ", ', , ©, …) to UTF-8. Unknown or malformed references are left verbatim. Inverse of escape for the characters it covers.
s | text that may contain character references. |
a newly allocated decoded copy.
O(n) time in the length of s.
one result string on the heap.
ParsersCompileRun.HtmlEscapeUnescapeTokenize an HTML document into the events a callback parser would dispatch.
Returns one Token per event, in document order. The Token::kind is one of:
"starttag"—<div class="x">; Token::tag + Token::attrs set."startendtag"— self-closing<br/>; tag + attrs set."endtag"—</div>; Token::tag set."data"— text between tags; Token::data set (character references decoded, like Python'sconvert_charrefs=True)."comment"—<!-- … -->; Token::data is the comment body."decl"—<!DOCTYPE html>; Token::data is the text after<!."pi"— processing instruction<? … >; Token::data the body.
Tag and attribute names are lowercased. <script> / <style> bodies are emitted as a single raw "data" token (references not decoded). Malformed input never throws: unterminated constructs consume to end-of-input.
html | the document text. |
the token list (empty for empty input).
O(n) time in the length of html.
the token vector and its strings on the heap.
ParsersCompileRun.HtmlParseWalkValue of attribute name on t, or "" if absent (or valueless).
t | a start/startend token. |
name | attribute name (matched case-insensitively). |
the attribute value, or "".
O(k) in the attribute count of t.
one result string on the heap.
ParsersHtml.GetAttrHasAttrLookupParsersCompileRun.HtmlAttrHelpersWhether t carries an attribute named name (case-insensitive).
t | a start/startend token. |
name | attribute name. |
true if present (even if valueless).
O(k) in the attribute count of t.
none.
ParsersHtml.GetAttrHasAttrLookupParsersCompileRun.HtmlAttrHelpers