html

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 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