package html
import "html"
Package html 提供用于转义和反转义 HTML 文本的函数。
Index
Examples
Functions
func EscapeString
func EscapeString(s string) string
EscapeString 将特殊字符(如 "<")转义为 "<"。
它仅转义五个这样的字符:<、>、&、' 和 "。
UnescapeString(EscapeString(s)) == s 始终成立,但反过来并不总是成立。
Output:Example
package main
import (
"fmt"
"html"
)
func main() {
const s = `"Fran & Freddie's Diner" <tasty@example.com>`
fmt.Println(html.EscapeString(s))
}
"Fran & Freddie's Diner" <tasty@example.com>
func UnescapeString
func UnescapeString(s string) string
UnescapeString 将实体(如 "<")反转义为 "<"。它能反转义的实体范围
比 EscapeString 转义的范围更大。例如,"á" 会被反转义为 "á",
"á" 和 "á" 也是如此。
UnescapeString(EscapeString(s)) == s 始终成立,但反过来并不总是成立。
Output:Example
package main
import (
"fmt"
"html"
)
func main() {
const s = `"Fran & Freddie's Diner" <tasty@example.com>`
fmt.Println(html.UnescapeString(s))
}
"Fran & Freddie's Diner" <tasty@example.com>
Directories
| template | Package template (html/template) 实现了数据驱动的模板,用于生成防止代码注入的安全 HTML 输出。 |