Strip HTML tags and render plain-text content only

This commit is contained in:
Christian Muehlhaeuser
2019-11-25 06:45:55 +01:00
parent 4c529d72b9
commit fb7c07f593
3 changed files with 13 additions and 3 deletions
+8 -3
View File
@@ -11,9 +11,14 @@ import (
"github.com/alecthomas/chroma/quick"
"github.com/logrusorgru/aurora"
"github.com/microcosm-cc/bluemonday"
bf "gopkg.in/russross/blackfriday.v2"
)
var (
stripper = bluemonday.StrictPolicy()
)
type Fragment struct {
Token string
Pre string
@@ -247,10 +252,10 @@ func NewElement(node *bf.Node) Element {
}
case bf.HTMLBlock:
return Element{
Pre: "\n",
Post: "\n",
Pre: "",
Post: "",
Fragments: []Fragment{{
Token: string(node.Literal),
Token: strings.TrimSpace(stripper.Sanitize(string(node.Literal))) + "\n",
Style: HTMLBlock,
}},
}