A HTML entity encoding library for Rust
Example usage
All example assume a extern crate htmlescape;
and use htmlescape::{relevant functions here};
is present.
###Encoding
htmlescape::encode_minimal()
encodes an input string using a minimal set of HTML entities.
let title = "Cats & dogs";
let tag = format!;
assert_eq!;
There is also a htmlescape::encode_attribute()
function for encoding strings that are to be used
as html attribute values.
###Decoding
htmlescape::decode_html()
decodes an encoded string, replacing HTML entities with the
corresponding characters. Named, hex, and decimal entities are supported. A Result
value is
returned, with either the decoded string in Ok
, or an error in Err
.
let encoded = "Cats & dogs";
let decoded = match decode_html ;
assert_eq!;
###Avoiding allocations
Both the encoding and decoding functions are available in forms that take a Writer
for output rather
than returning an String
. These version can be used to avoid allocation and copying if the returned
String
was just going to be written to a Writer
anyway.