Skip to main content

Module html

Module html 

Source
Expand description

UI-10: HTML the page may hold — {@html expr} draws the expression’s text as HTML, and markdown(text) makes HTML of markdown; both go through sanitize first.

The sanitizer is an allow-list: it parses the text into elements and text, keeps a tag only when it is listed (ALLOWED_TAGS) and an attribute only when it is listed for its tag (allowed_attr); a URL attribute keeps only http:, https:, #… and mailto: values. A tag not listed is dropped and its text kept — except script, style, iframe, object, embed, noscript, template, svg and math, dropped with everything inside. What it answers is a tree the engine draws through the renderer: no HTML string reaches the page.

Enums§

HNode
A sanitized node.

Constants§

ALLOWED_ATTRS
Every (tag, attribute) kept; * is any allowed tag. Widening it is a deliberate edit (html/tests.rs pins it).
ALLOWED_TAGS
The tags kept.
HOUSE_ATTRS
The plain-text attributes a house mark keeps beside data-* (and id, kept as data-id: an element’s id names a global on window).
PROP_PREFIX
COMPS-4: where a house mark’s or a custom tag’s other attributes go — a tag in a body names a component, its attributes its props: kept inert under this prefix (<x-counter start="3"> → data-prop-start="3").

Functions§

allowed_attr
Whether attr is kept on tag (ALLOWED_ATTRS; on a house mark, house_attr).
custom_tag
EDITOR-9: a custom element’s name — letters, digits and -, with a -, beginning with a letter (volt-poll, x-new); not a house mark’s (those stay themselves).
house_attr
Whether a house mark keeps attr: a data-* (letters, digits, -) but the bound mark’s four, or one of HOUSE_ATTRS. No handler, no style, no URL.
house_tag
EDITOR-8: a house mark — m-<name> (m-summary, m-field, m-decision, …), letters, digits and - after the m-. A tenant’s body draws its marks as cards in CSS (the element is inert: no script defines it here, and nothing on it loads or runs), so the tag is kept with the plain-text attributes its card reads (house_attr) and nothing else.
markdown
Markdown as HTML (CommonMark with tables and strikethrough); raw HTML in it passes through, to be sanitized where it is drawn.
prop_attr
COMPS-4: an attribute kept as a prop (PROP_PREFIX) — letters, digits and -, beginning with a letter; never a handler (on…), a style, a URL (href, src) or a data-* (those are house_attr’s, the bound mark’s dropped).
sanitize
html, parsed and kept to the allow-list.
to_html
The nodes as HTML text (escaped), for the tests and the console.