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 Try out

{{ "<p>This is a paragraph</p>" | html.strip }}

output

This is a paragraph

html.escape

html.escape <text>

Description

Escapes a HTML input string (replacing & by &amp;)

Arguments

  • text: The input string

Returns

The input string removed with any HTML tags

Examples

input Try out

{{ "<p>This is a paragraph</p>" | html.escape }}

output

&lt;p&gt;This is a paragraph&lt;/p&gt;

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 Try out

{{ "Hello\nworld" | html.newline_to_br }}

output

Hello<br />
world

html.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 Try out

{{ "john@liquid.com" | html.url_encode }}

output

john%40liquid.com

html.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 Try out

{{ "<hello> & <scriban>" | html.url_escape }}

output

%3Chello%3E%20&%20%3Cscriban%3E