version: 1.10

package html

import "html"

Overview

Package html provides functions for escaping and unescaping HTML text.

Index

Examples

Package files

entity.go escape.go

func EscapeString

  1. func EscapeString(s string) string

EscapeString escapes special characters like “<” to become “<”. It escapes only five such characters: <, >, &, ‘ and “. UnescapeString(EscapeString(s)) == s always holds, but the converse isn’t always true.

Example:

  1. const s = `"Fran & Freddie's Diner" <tasty@example.com>`
  2. fmt.Println(html.EscapeString(s))
  3. // Output: &#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;tasty@example.com&gt;

func UnescapeString

  1. func UnescapeString(s string) string

UnescapeString unescapes entities like “<” to become “<”. It unescapes a larger range of entities than EscapeString escapes. For example, “á” unescapes to “á”, as does “á” and “á”. UnescapeString(EscapeString(s)) == s always holds, but the converse isn’t always true.

Example:

  1. const s = `&quot;Fran &amp; Freddie&#39;s Diner&quot; &lt;tasty@example.com&gt;`
  2. fmt.Println(html.UnescapeString(s))
  3. // Output: "Fran & Freddie's Diner" <tasty@example.com>

Subdirectories