Move ANSIRenderer into a separate package

This commit is contained in:
Christian Muehlhaeuser
2019-12-14 00:11:29 +01:00
parent 3018ad9a32
commit 4b65ed22c2
21 changed files with 245 additions and 227 deletions
+35
View File
@@ -0,0 +1,35 @@
package ansi
import (
"html"
"strings"
"github.com/microcosm-cc/bluemonday"
)
type RenderContext struct {
options Options
blockStack *BlockStack
table *TableElement
stripper *bluemonday.Policy
}
func NewRenderContext(options Options) RenderContext {
return RenderContext{
options: options,
blockStack: &BlockStack{},
table: &TableElement{},
stripper: bluemonday.StrictPolicy(),
}
}
func (ctx RenderContext) SanitizeHTML(s string, trimSpaces bool) string {
s = ctx.stripper.Sanitize(s)
if trimSpaces {
s = strings.TrimSpace(s)
}
return html.UnescapeString(s)
}