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

Converts any URL-unsafe characters in a string into percent-encoded characters.

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

Identifies all characters in a string that are not allowed in URLS, and replaces the characters with their escaped variants.

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

Note: This document was automatically generated from the source code using Scriban.DocGen.