HtmlEscape class final
Converter which escapes characters with special meaning in HTML.
The converter finds characters that are significant in the HTML source and replaces them with corresponding HTML entities.
The characters that need escaping in HTML are:
&
(ampersand) always needs to be escaped.<
(less than) and>
(greater than) when inside an element."
(quote) when inside a double-quoted attribute value.'
(apostrophe) when inside a single-quoted attribute value. Apostrophe is escaped as'
instead of'
since not all browsers understand'
./
(slash) is recommended to be escaped because it may be used to terminate an element in some HTML dialects.
Escaping >
(greater than) isn't necessary, but the result is often
found to be easier to read if greater-than is also escaped whenever
less-than is.
Example:
const HtmlEscape htmlEscape = HtmlEscape();
String unescaped = 'Text & subject';
String escaped = htmlEscape.convert(unescaped);
print(escaped); // Text & subject
unescaped = '10 > 1 and 1 < 10';
escaped = htmlEscape.convert(unescaped);
print(escaped); // 10 > 1 and 1 < 10
unescaped = "Single-quoted: 'text'";
escaped = htmlEscape.convert(unescaped);
print(escaped); // Single-quoted: 'text'
unescaped = 'Double-quoted: "text"';
escaped = htmlEscape.convert(unescaped);
print(escaped); // Double-quoted: "text"
unescaped = 'Path: /system/';
escaped = htmlEscape.convert(unescaped);
print(escaped); // Path: /system/
Constructors
- HtmlEscape([HtmlEscapeMode mode = HtmlEscapeMode.unknown])
-
Create converter that escapes HTML characters.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- mode → HtmlEscapeMode
-
The HtmlEscapeMode used by the converter.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
Stream< String> stream) → Stream<String> -
Transforms the provided
stream
.inherited -
cast<
RS, RT> () → Converter< RS, RT> -
Provides a
Converter<RS, RT>
view of this stream transformer.inherited -
convert(
String text) → String -
Converts
input
and returns the result of the conversion.override -
fuse<
TT> (Converter< String, TT> other) → Converter<String, TT> -
Fuses
this
withother
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startChunkedConversion(
Sink< String> sink) → StringConversionSink -
Starts a chunked conversion.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited