HtmlDecode - ObjectVision/GeoDMS GitHub Wiki
String functions HtmlDecode
The HtmlDecode function decodes HTML-encoded strings back to their original form.
HtmlDecode(strings: E->String) -> E->String
Converts HTML-encoded strings back to their original format by replacing HTML entity references with the corresponding characters:
| Entity | Character |
|---|---|
< |
< |
> |
> |
& |
& |
" |
" |
' |
' |
|
no-break space (U+00A0, two bytes in UTF-8) |
The first five are the predefined XML/HTML entities that HtmlEncode produces, so HtmlDecode(HtmlEncode(x)) returns x. is accepted as well because it is ubiquitous in HTML, although HtmlEncode never produces it.
Also decodes numeric character references, decimal < as well as hexadecimal <, emitting the code point as UTF-8.
Anything that is not a reference this function knows is copied through verbatim rather than being an error: an unknown name (&unknown;), an unterminated reference (& x) and an out-of-range numeric reference all stay as they are, since that is what the input meant literally. &lt; therefore decodes to <, not to <: decoding is applied once, not repeatedly.
| argument | description | type |
|---|---|---|
| strings | HTML-encoded strings to decode | E->String |
Time complexity: O(n × L) where n is the number of strings and L is the average string length.
Decoded strings are typically slightly shorter than input strings.
unit<uint32> HtmlContent: nrofrows = 3;
attribute<String> encoded (HtmlContent) := union_data(HtmlContent,
'Hello <world>',
'A & B',
'Quote: "test"'
);
attribute<String> decoded (HtmlContent) := HtmlDecode(encoded);
// decoded = {'Hello <world>', 'A & B', 'Quote: "test"'}
- Processing data extracted from HTML sources
- Converting HTML content to plain text
- Cleaning up HTML entity artifacts in imported data
- HtmlEncode - reverse operation
- UrlDecode - for URL parameters
- String functions
20.13.0