• Ecapes a string and converts traces of HTML characters that could be wrongfully interpreted as markup. The following characters are reserved in HTML and must be replaced with their corresponding HTML entities:

    • " is replaced with "
    • & is replaced with &
    • < is replaced with &lt;
    • > is replaced with &gt;

    Parameters

    • text: string
    • encodeSpace: boolean = false

      Shall space ( ) be replaced with &nbsp;.

    • encodeNewline: boolean = false

      Shall line break (\n) be replaced with &lt;br&gt;.

    Returns string

    Example

    ix.util.htmlEncode('<a href="https://foobar?rq_foo=bar&rq_bar=foo">encode me </a>');
    // returns: "&lt;a href=&quot;https://foobar?rq_foo=bar&amp;rq_bar=foo&quot;&gt;encode me &lt;/a&gt;"

    Example

    ix.util.htmlEncode("<h1>example</h1>\n<p>my cool paragraph</p>", true, true);
    // returns: "&lt;h1&gt;example&lt;/h1&gt;&lt;br&gt;&lt;p&gt;my&nbsp;cool&nbsp;paragraph&lt;/p&gt;"