HEsc class

HTML escaping methods for escaping values for output in HTML.

These methods are provided to help generate HTML from arbitrary strings and other objects.

Use attr to escape values to be used in attributes. Use text to escape values to be used in CDATA content. Use lines to escape values to be used in CDATA content, where line breaks are to be indicated with <br/> tags.

Examples:

var alpha = 'Don't use <blink>Flash</blink> & "stuff" in HTML.';
var beta = "1. First line\n2. second line\n3. third line";

resp.write("""
<div title="${HEsc.attr(alpha)}">
  <p>${HEsc.text(alpha)}</p>
  <p>${HEsc.text(123)}</p>
  <p>${HEsc.lines(beta)}</p>
</div>
""");

Writes out:

<div title="Don&apos;t use &lt;blink&gt;Flash&lt;/blink&gt; &amp; &quot;stuff&quot;.">
  <p>Don't use &lt;blink&gt;Flash&lt;/blink&gt; &amp; other "stuff".</p>
  <p>123</p>
  <p>1. First line<br/>2. second line<br/>3. third line</p>
</div>

Constructors

HEsc()

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited

Static Methods

attr(Object value) → String
Escape values for placement inside a HTML or XML attribute. [...]
lines(Object value) → String
Format multi-line text for placement inside a HTML element. [...]
text(Object value) → String
Escape values for placement inside the contents of a HTML or XML element. [...]