glentities
Types
pub type EncodeMode {
Named
Hex
HTMLBody
}
Constructors
-
Named
Encode all characters that have a specified named entity using that name, except tab and newline.
-
Hex
Encode all characters using hex entities, except a-z, A-Z, 0-9, newline, tab, carriage return, and space.
-
HTMLBody
Encode only the necessary characters when the output target is HTML element or attribute content.
This means
&
,<
,>
,'
, and"
.Note! Not suitable for outputting inside
<style>
,<script>
elements.
Functions
pub fn decode_dec(entity: String) -> String
Decode given entity (without surrounding &#
and ;
) as decimal entity. Returns original if cannot be decoded.
pub fn decode_hex(entity: String) -> String
Decode given entity (without surrounding &#x
and ;
) as hex entity. Returns original if cannot be decoded.
pub fn decode_named(entity: String) -> String
Decode given entity (without surrounding &
and ;
) as a named entity. Returns original if it doesn’t match any entity name.
pub fn encode(text: String, mode: EncodeMode) -> String
Encode characters in text as HTML entities with given encoding mode.
pub fn encode_hex(text: String) -> String
Encode text using HTML hex entities, except a-z, A-Z, 0-9, newline, tab, carriage return, and space.
pub fn encode_html_body(text: String, acc: StringBuilder) -> String
Encode text to be safe in the HTML body, inside element or attribute content.
&
, <
, >
, '
, and "
are encoded.
Note! Not suitable for outputting inside <style>
, <script>
elements.
pub fn encode_named(text: String, acc: StringBuilder) -> String
Encode text using named HTML entities, except newline and tab. Characters without a named entity are untouched.