Documentation
¶
Overview ¶
Package html extends the standard Go html package with more comprehensive HTML escaping capabilities.
While the standard library's html.EscapeString only escapes a minimal set of characters ('<', '>', '&', ”', '"'), this package provides an EscapeString function that converts a much wider range of characters into their corresponding HTML named character references from the W3C specification. This includes support for two-codepoint composite characters and ensures all entities are semicolon-terminated.
For convenience, aliases for the standard library's html.EscapeString (EscapeStringStd) and html.UnescapeString are also provided.
A key invariant of this package is that for any string `s`, `UnescapeString(EscapeString(s)) == s`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // EscapeStringStd is an alias for the standard library's [html.EscapeString], // which escapes only the characters <, >, &, ', and ". EscapeStringStd = html.EscapeString // UnescapeString is an alias for the standard library's [html.UnescapeString]. UnescapeString = html.UnescapeString )
Functions ¶
func EscapeString ¶
EscapeString escapes a wider range of HTML characters than the standard html.EscapeString function. It uses the full entity map from W3C to convert characters like "é" to "é" and "α" to "α". It also escapes basic HTML characters like "<" to "<". EscapeString is the inverse of UnescapeString, meaning that UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.
Types ¶
This section is empty.