okami.mom/glamour
git clone https://git.nkp.pet/okami.mom/glamour
4046973
main
1package ansi 2 3import ( 4"html" 5"strings" 6 7"github.com/microcosm-cc/bluemonday" 8) 9 10// RenderContext holds the current rendering options and state. 11type RenderContext struct { 12options Options 13 14blockStack * BlockStack 15table * TableElement 16 17stripper * bluemonday.Policy 18} 19 20// NewRenderContext returns a new RenderContext. 21func NewRenderContext (options Options )RenderContext { 22return RenderContext { 23options :options , 24blockStack :& BlockStack {}, 25table :& TableElement {}, 26stripper :bluemonday .StrictPolicy (), 27 } 28} 29 30// Width is the width left for content inside the current block. 31func (ctx RenderContext )Width ()int { 32return int (ctx .blockStack .Width (ctx )) 33} 34 35// Styles is the style configuration being rendered with. 36func (ctx RenderContext )Styles ()StyleConfig { 37return ctx .options .Styles 38} 39 40// SanitizeHTML sanitizes HTML content. 41func (ctx RenderContext )SanitizeHTML (s string ,trimSpaces bool )string { 42s = ctx .stripper .Sanitize (s ) 43if trimSpaces { 44s = strings .TrimSpace (s ) 45 } 46 47return html .UnescapeString (s ) 48}