html functionsHtml functions available through the builtin object 'html'.
html.striphtml.strip <text>
Removes any HTML tags from the input string
text: The input stringThe input string removed with any HTML tags
Notice that the implementation of this function is using a simple regex, so it can fail escaping correctly or timeout in case of the malformed html. If you are looking for a secure HTML stripped, you might want to plug your own HTML function by using AngleSharp to strip these HTML tags.
input Try out
{{ "<p>This is a paragraph</p>" | html.strip }}
output
This is a paragraph
html.escapehtml.escape <text>
Escapes a HTML input string (replacing & by &)
text: The input stringThe input string removed with any HTML tags
input Try out
{{ "<p>This is a paragraph</p>" | html.escape }}
output
<p>This is a paragraph</p>
html.newline_to_brhtml.newline_to_br <text>
Inserts an HTML line break (<br /> in front of each newline (\r\n, \r, \n) in a string
text: The input stringThe input string with HTML line breaks
input Try out
{{ "Hello\nworld" | html.newline_to_br }}
output
Hello<br />
world
html.url_encodehtml.url_encode <text>
Percent-encodes a string for use as a URL component.
This function encodes URL syntax characters such as :, /, ?, #, &, =, and '. Spaces are encoded as %20.
It does not validate complete URLs and does not make arbitrary input safe for every output context. When writing a value
into an HTML attribute, validate complete URLs separately and HTML-escape the attribute value.
text: The input stringThe input string URL encoded
input Try out
{{ "john@liquid.com" | html.url_encode }}
output
john%40liquid.com
html.url_escapehtml.url_escape <text>
Escapes characters that are not valid in a complete URL while preserving URL syntax characters.
This function is intended for already-formed, trusted or validated URLs and paths. It preserves reserved URL syntax
characters such as :, /, ?, #, &, =, and '. It does not validate schemes or hosts and must not be used
as a sanitizer for untrusted href or src values. Use html.url_encode for untrusted URL components or query values.
text: The input stringThe input string URL escaped
input Try out
{{ "<hello> & <scriban>" | html.url_escape }}
output
%3Chello%3E%20&%20%3Cscriban%3E
This document was automatically generated from the source code using Scriban.DocGen.