Documentation
¶
Overview ¶
Package html converts between HTML and plain text, sanitizes untrusted markup, and extracts summaries from HTML documents.
FromText escapes plain text into lightly-formatted HTML. ToText and ToSearchText strip markup back down to text, and Summary produces a short plain-text excerpt truncated on a rune boundary. RemoveTags, RemoveAnchors, RemoveSpecialCharacters, and CollapseWhitespace handle the narrower cleanups, and IsHTML reports whether a string appears to contain markup at all.
Minimal is the trust boundary. It is the only function here that sanitizes: a bluemonday policy plus an explicit element allow-list, and the one thing to run untrusted markup through before rendering it. Everything else in this package cleans or escapes without making any safety promise about tags that were already present.
Index ¶
- func CollapseWhitespace(text string) string
- func FromText(text string) string
- func IsHTML(html string) bool
- func Minimal(text string) string
- func RemoveAnchors(html string) string
- func RemoveSpecialCharacters(html string) string
- func RemoveTags(html string) string
- func Summary(html string) string
- func ToSearchText(html string) string
- func ToText(html string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollapseWhitespace ¶
CollapseWhitespace converts all whitespace characters into a single SPACE character
func IsHTML ¶
IsHTML returns TRUE if the string provided "looks like" HTML, in that, it has one or more substrings that appear to be an HTML tag
func Minimal ¶ added in v0.19.0
Minimal sanitizes the provided HTML, allowing only a minimal set of formatting elements.
func RemoveAnchors ¶ added in v0.20.0
RemoveAnchors strips all HTML anchor tags from a string.
func RemoveSpecialCharacters ¶ added in v0.20.0
RemoveSpecialCharacters removes special Unicode characters from a string
func RemoveTags ¶
RemoveTags aggressively strips HTML tags from a string. It will only keep anything between `>` and `<`. From: https://stackoverflow.com/questions/55036156/how-to-replace-all-html-tag-with-empty-string-in-golang Original code by: Daniel Morell <https://stackoverflow.com/users/10463261/daniel-morell>
func ToSearchText ¶ added in v0.20.0
ToSearchText removes tags in a way that is suitable to text searches. This means that it will remove all tags, but adds regular whitespace in between them.
Types ¶
This section is empty.