Reference · Markup
raw
raw(any) -> htmlWhat it does
Marks text as trusted HTML: the result is an html value, which markup writes as it
is instead of escaping it. Use it for HTML you made yourself or stored from markdown,
never for what a visitor typed. Any value is taken; its text is what str gives.
raw(t(key, vars)) is a special form: the translation's markup is kept and the values
put into it are escaped.
Examples
let h = raw("<b>bold</b>")print(h, str(h))print(raw(42), raw(true))<b>bold</b> <b>bold</b>42 trueEdge cases
- An
htmlvalue is not equal to a string with the same text;str(...)is. rawof anhtmlvalue (markdown's result) is the same value.escapeturns it back into text:escape(raw(x))shows the tags.nullgives the textnull, not an empty value.- Inside
<script>{...}</script>, anhtmlvalue goes in as it is except that</becomes<\/and<!--becomes<\!--, so it cannot end the element early. - HTML a visitor wrote, even cleaned by a sanitizer, must not keep the attributes
Quillo's islands are made of,
data-qi,data-qd,data-qt,data-c,data-p,data-s,data-l,data-vanddata-e, nor<quillo-island>elements: the page takes such an element up as one of its components, with the props and state it says. DOMPurify keepsdata-*unless told not to (ALLOW_DATA_ATTR: false).
print(raw("x") == "x", str(raw("x")) == "x")print(raw(markdown("*a*")) == markdown("*a*"))print(escape(raw("<b>")))print(raw(null), raw(""))translations({ en: { welcome: "Welcome, <b>{name}</b>" } })print(raw(t("welcome", { name: "<i>Ada</i>" })))false truetrue<b>null Welcome, <b><i>Ada</i></b>Errors
None: every value has a text, so raw never fails and never gives an error value.
What it marks is trusted, so the error to avoid is a visitor's text in it.
print(raw(err("x")))err("x")Chaining
print(["<li>a</li>", "<li>b</li>"] | join("") | raw)let safe = "<b>" | escape | rawprint(safe)<li>a</li><li>b</li><b>view Post(p) = <article> <h2>{p.title}</h2> {raw(p.body_html)}</article>See also
escape, markdown, highlight, t
Thread 0 posts
On raw(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo