HTML (std)
std/html is written in Agentica and has the behaviour of Ruby’s CGI.escape_html and CGI.unescape_html: import HTML from "std/html". Nothing in it halts, whatever the input.
HTML.escape(text: String) -> String
HTML.unescape(text: String) -> Stringimport HTML from "std/html"
def main() -> Void
puts(HTML.escape("<a href=\"/?q=1&r='2'\">"))
puts(HTML.unescape("<b> 😀 A &lt;"))
end<a href="/?q=1&r='2'">
<b> ๐ A <escape replaces &, <, >, " and ' with &, <, >, " and ', as Ruby does.
unescape decodes &, <, >, ", ', decimal A and hex A (A too), and nothing else. Other text that looks like an entity stays as written: a name Ruby does not know ( ), a missing ;, and a number that is not a Unicode scalar value (above 10FFFF, or a surrogate). For such a number Ruby may raise or leave the text, depending on its version; this behaviour may differ from Ruby there. unescape("�") gives a NUL character, as Ruby does. The text is read once, so &lt; becomes <, and unescape(escape(text)) is text.