MCPcopy Index your code
hub / github.com/git-bug/git-bug / stripHTML

Method stripHTML

bridge/gitlab/parser/parser.go:85–107  ·  view source on GitHub ↗

stripHTML removes all html tags from a provided string

(s string)

Source from the content-addressed store, hash-verified

83
84// stripHTML removes all html tags from a provided string
85func (p titleParser) stripHTML(s string) (string, error) {
86 nodes, err := html.Parse(strings.NewReader(s))
87 if err != nil {
88 // return the original unmodified string in the event html.Parse()
89 // fails; let the downstream callsites decide if they want to proceed
90 // with the value or not.
91 return s, err
92 }
93
94 var buf bytes.Buffer
95 var walk func(*html.Node)
96 walk = func(n *html.Node) {
97 if n.Type == html.TextNode {
98 buf.WriteString(n.Data)
99 }
100 for c := n.FirstChild; c != nil; c = c.NextSibling {
101 walk(c)
102 }
103 }
104 walk(nodes)
105
106 return buf.String(), nil
107}

Callers 1

ParseMethod · 0.95

Calls 2

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected