Reference · Markup
escape
signature
escape(any) -> strWhat it does
The value's text with & < > " ' written as entities (& < > " '), safe to put inside an element or an attribute. Markup escapes text by
itself, so this is for HTML built as a string: a piece you then mark with raw, or
text written into a file. Any value is taken; its text is what str gives.
Examples
print(escape("<b>Tom & Jerry's \"show\"</b>"))print(escape(42), escape(true), escape("plain"))output
<b>Tom & Jerry's "show"</b>42 true plainEdge cases
- An
htmlvalue is escaped like text:escape(markdown(...))shows the tags. - Escaping twice doubles the entities:
<becomes&lt;. nullgives the textnull, not the empty string.- A list or a map gives its printed form, escaped.
- Letters outside ASCII,
\nand spaces stay as they are. A CR is written and a NUL U+FFFD, here and in markup, on the server and in the browser, so a note typed in a<textarea>and posted with CRLF is taken up as written.
print(escape(markdown("*a*")))print(escape(escape("<")))print(escape(null), escape(""))print(escape([1, "<"]), escape({ a: "<" }))print(escape("héllo\n😀"))output
<p><em>a</em></p>&lt;null [1, "<"] { a: "<" }héllo😀Errors
None: every value has a text, so escape never fails and never gives an error value.
An error value is shown as err(...), escaped.
print(escape(err("<bad>")))output
err("<bad>")Chaining
print(["<a>", "b & c"] | map(escape) | join(", "))let cell = "<script>" | escapeprint(raw(`<td>${cell}</td>`))output
<a>, b & c<td><script></td>See also
raw, url_encode, markdown, str
Thread
Thread 0 posts
On escape(): 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