Reference · Markup

raw

signature
raw(any) -> html

What 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))
output
<b>bold</b> <b>bold</b>42 true

Edge cases

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>" })))
output
false truetrue&lt;b&gt;null Welcome, <b>&lt;i&gt;Ada&lt;/i&gt;</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")))
output
err("x")

Chaining

print(["<li>a</li>", "<li>b</li>"] | join("") | raw)let safe = "<b>" | escape | rawprint(safe)
output
<li>a</li><li>b</li>&lt;b&gt;
in a program
view Post(p) = <article>    <h2>{p.title}</h2>    {raw(p.body_html)}</article>

See also

escape, markdown, highlight, t

Thread
6Useful? Like it, or add to its thread below.

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