Categorygithub.com/grokify/html-strip-tags-go
modulepackage
0.1.0
Repository: https://github.com/grokify/html-strip-tags-go.git
Documentation: pkg.go.dev

# README

HTML StripTags for Go

Used By Build Status Go Report Card Docs License

This is a Go package containing an extracted version of the unexported stripTags function in html/template/html.go.

:warning: This package does not protect against untrusted input. Please use bluemonday if you have untrusted data :warning:

Background

  • The stripTags function in html/template/html.go is very useful, however, it is not exported.
  • Requests were made on GitHub without success.
  • This package is a repo for work done by Christopher Hesse provided in this Gist.

Installation

$ go get github.com/grokify/html-strip-tags-go

Usage

import(
    "github.com/grokify/html-strip-tags-go" // => strip
)

func main() {
    original := "<h1>Hello World</h1>"
    stripped := strip.StripTags(original) // => "Hello World"
}

# Functions

HTMLEscape writes to w the escaped HTML equivalent of the plain text data b.
HTMLEscaper returns the escaped HTML equivalent of the textual representation of its arguments.
HTMLEscapeString returns the escaped HTML equivalent of the plain text data s.
JSEscape writes to w the escaped JavaScript equivalent of the plain text data b.
JSEscaper returns the escaped JavaScript equivalent of the textual representation of its arguments.
JSEscapeString returns the escaped JavaScript equivalent of the plain text data s.
Must is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil.
New allocates a new HTML template with the given name.
ParseFiles creates a new Template and parses the template definitions from the named files.
ParseGlob creates a new Template and parses the template definitions from the files identified by the pattern, which must match at least one file.
stripTags takes a snippet of HTML and returns only the text content.
URLQueryEscaper returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query.

# Constants

ErrAmbigContext: "..
ErrBadHTML: "expected space, attr name, or end of tag, but got ...", "..
ErrBranchEnd: "{{if}} branches end in different contexts" Example: {{if .C}}<a href="{{end}}{{.X}} Discussion: Package html/template statically examines each path through an {{if}}, {{range}}, or {{with}} to escape any following pipelines.
ErrEndContext: "..
ErrNoSuchTemplate: "no such template ..." Examples: {{define "main"}}<div {{template "attrs"}}>{{end}} {{define "attrs"}}href="{{.URL}}"{{end}} Discussion: Package html/template looks through template calls to compute the context.
ErrOutputContext: "cannot compute output context for template ..." Examples: {{define "t"}}{{if .T}}{{template "t" .T}}{{end}}{{.H}}",{{end}} Discussion: A recursive template does not end in the same context in which it starts, and a reliable output context cannot be computed.
ErrPartialCharset: "unfinished JS regexp charset in ..." Example: <script>var pattern = /foo[{{.Chars}}]/</script> Discussion: Package html/template does not support interpolation into regular expression literal character sets.
ErrPartialEscape: "unfinished escape sequence in ..." Example: <script>alert("\{{.X}}")</script> Discussion: Package html/template does not support actions following a backslash.
ErrRangeLoopReentry: "on range loop re-entry: ..." Example: <script>var x = [{{range .}}'{{.}},{{end}}]</script> Discussion: If an iteration through a range would cause it to end in a different context than an earlier pass, there is no single context.
ErrSlashAmbig: '/' could start a division or regexp.
OK indicates the lack of an error.

# Structs

Error describes a problem encountered during template Escaping.
Template is a specialized Template from "text/template" that produces a safe HTML document fragment.

# Type aliases

Strings of content from a trusted source.
ErrorCode is a code for a kind of error.
FuncMap is the type of the map defining the mapping from names to functions.
Strings of content from a trusted source.
Strings of content from a trusted source.
Strings of content from a trusted source.
Strings of content from a trusted source.
Strings of content from a trusted source.