How to render string to html / escape for html

How do I render a string into html?

For example s = "x < y"; render(s) should become "x &lt; y".

This works but it’s a little verbose:

using HypertextLiteral
let io = IOBuffer()
    print(io, HypertextLiteral.Result(HypertextLiteral.content(s)))
    seekstart(io)
    read(io, String)
end
"x &lt; y"

Using the standard library:

using Markdown
s = "x < y"
Markdown.htmlesc(s)      # "x &lt; y"
2 Likes