mirror of
https://github.com/miniflux/v2.git
synced 2024-09-11 05:33:18 +02:00
35 lines
688 B
Go
35 lines
688 B
Go
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package sanitizer // import "miniflux.app/reader/sanitizer"
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"golang.org/x/net/html"
|
|
)
|
|
|
|
// StripTags removes all HTML/XML tags from the input string.
|
|
func StripTags(input string) string {
|
|
tokenizer := html.NewTokenizer(bytes.NewBufferString(input))
|
|
var buffer bytes.Buffer
|
|
|
|
for {
|
|
if tokenizer.Next() == html.ErrorToken {
|
|
err := tokenizer.Err()
|
|
if err == io.EOF {
|
|
return buffer.String()
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
token := tokenizer.Token()
|
|
switch token.Type {
|
|
case html.TextToken:
|
|
buffer.WriteString(token.Data)
|
|
}
|
|
}
|
|
}
|