Html functions
Html functions available through the builtin object html.
html.strip
html.strip <text>Description
Removes any HTML tags from the input string
Arguments
text: The input string
Returns
The input string removed with any HTML tags
Examples
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
{{ "<p>This is a paragraph</p>" | html.strip }}output
This is a paragraphhtml.escape
html.escape <text>Description
Escapes a HTML input string (replacing & by &)
Arguments
text: The input string
Returns
The input string removed with any HTML tags
Examples
input
{{ "<p>This is a paragraph</p>" | html.escape }}output
<p>This is a paragraph</p>html.newline_to_br
html.newline_to_br <text>Description
Inserts an HTML line break (<br /> in front of each newline (\r\n, \r, \n) in a string
Arguments
text: The input string
Returns
The input string with HTML line breaks
Examples
input
{{ "Hello\nworld" | html.newline_to_br }}output
Hello<br />
worldhtml.url_encode
html.url_encode <text>Description
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.
Arguments
text: The input string
Returns
The input string URL encoded
Examples
input
{{ "john@liquid.com" | html.url_encode }}output
john%40liquid.comhtml.url_escape
html.url_escape <text>Description
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.
Arguments
text: The input string
Returns
The input string URL escaped
Examples
input
{{ "<hello> & <scriban>" | html.url_escape }}output
%3Chello%3E%20&%20%3Cscriban%3E