Help us shape the future of Go! Take the 2026 Go Developer Survey

html

package
v0.11.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 3 Imported by: 2

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

View Source
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

func EscapeString(s string) string

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 "&eacute;" and "α" to "&alpha;". It also escapes basic HTML characters like "<" to "&lt;". 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL