std1.0.0-beta-7 SafeC docs

Module serial::html

#include <std/serial/html.h> source

HTML serialization (built on std/serial/value.h)

Same Value tree as json.h/xml.h. Unlike JSON/XML, HTML isn't itself a data-interchange format, so 'html_write' renders a Value tree as a human-readable document fragment rather than something meant to be parsed back:

- VAL_OBJECT  -> <dl><dt>key</dt><dd>...</dd>...</dl>  (definition list)
- VAL_ARRAY   -> <ul><li>...</li>...</ul>
- VAL_STRING/INT/FLOAT/BOOL -> escaped text
- VAL_NULL    -> <em>null</em>

This is deliberately the same shape as json_write/xml_write (a Value tree in, escaped markup text out) for consistency across the three format backends, even though "parse HTML back into a Value" isn't a meaningful operation the way JSON/XML decoding is.

Structs

HtmlThe HTML fragment backend as a Format (see value.h): v.encode(Html::new()), Value::decode(Html::new(), text, &ok) — the same as html_write / html_parse.

Functions

html_escapeEscapes '&', '<', '>', '"' for safe inclusion in HTML text/attribute content — useful on its own, independent of the Value-tree renderer below, for anything that needs to drop untrusted text into HTML.
html_unescapeThe reverse: appends 's' to 'out' with character references decoded — numeric (''', '—', as UTF-8) and the common named ones (amp lt gt quot apos nbsp, plus copy reg trade hellip mdash ndash lsquo rsquo ldquo rdquo laquo raquo middot bull times divide deg larr rarr uarr darr harr ne le ge); anything else is copied as-is.
html_strip_tagsAppends the text content of the HTML fragment 's' to 'out': tags and comments removed, <script>/<style> content dropped, and a single space standing in for each block-level boundary (</p>, <br>, </li>, </td>, </h2>, ...) so words in adjacent blocks don't run together. Character references are left as they are (follow with html_unescape for text).
html_writeAppends v's rendered HTML fragment to 'out'.
value_to_htmlConvenience wrapper: a fresh String holding just that fragment.
html_parseParses this module's own <dl>/<ul>/<em>null</em>/text fragment shape back into a Value tree. Sets *ok to 0 (and returns VAL_NULL) on malformed input. Not a general HTML parser — see html.sc's parser section for the two structural ambiguities inherent to this grammar (same as xml_parse's: empty string vs. empty container; numeric-looking text vs. string).