Custom HTML Helpers

October 4, 2018 ยท View on GitHub

These helpers provide some ability to manage strings for use within html content.


Helpers.Html.Escape

SummaryAn escape function similar to what exists in javascript. This will compute a new string which certain characters have been replaced by a hexadecimal escape sequence
ReturnsThe newly escaped string
Remarks/ characters will be escaped with a |
Parameters
strString to escape

Example

Context

{
    "value": "https://github.com/arinet/HandlebarDocs/blob/master/html.md#helpershtmlescape"
}

Usage

<strong>result:</strong>
{{Helpers.Html.Escape value}}

Returns

<strong>result:</strong>
https:\/\/github.com\/arinet\/HandlebarDocs\/blob\/master\/docs\/html.md#helpershtmlescape

Helpers.Html.HtmlDecode

SummaryConverts a string that has been HTML-encoded for HTTP transmission
ReturnsDecoded string
RemarksIf characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as < and > for HTTP transmission.
Parameters
htmlString to decode

Example

Context

{
    "value": "Enter a string having &#39;&amp;&#39; or &#39;&quot;&#39;  in it:"
}

Usage

<strong>result:</strong>
{{Helpers.Html.HtmlDecode value}}

Returns

<strong>result:</strong>
Enter a string having '&' or '"'  in it:

Helpers.Html.HtmlEncode

SummaryConverts a string to an HTML-encoded string
ReturnsEncoded string
RemarksIf characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as < and > for HTTP transmission.
Parameters
htmlString to encode

Example

Context

{
    "value": "Enter a string having '&' or '\"'  in it:"
}

Usage

<strong>result:</strong>
{{Helpers.Html.HtmlEncode value}}

Returns

<strong>result:</strong>
Enter a string having &#39;&amp;&#39; or &#39;&quot;&#39;  in it: