html

package
v0.11.17 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 3 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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