1 package bbcode 2 3 import ( 4 "bytes" 5 "text/template" 6 ) 7 8 var ( 9 // HTMLText is a text processor that will HTML encode all text output 10 HTMLText htmlText 11 // PlainText is a text processor that just outputs all text with no change 12 PlainText plainText 13 ) 14 15 type htmlText struct{} 16 17 var ( 18 newLine = []byte{'\n'} 19 newLineHTML = []byte{'<', 'b', 'r', ' ', '/', '>'} 20 ) 21 22 func (htmlText) Name() string { 23 return "" 24 } 25 26 func (htmlText) Handle(p *Processor, text string) { 27 for n, line := range bytes.Split([]byte(text), newLine) { 28 if n > 0 { 29 p.Write(newLineHTML) 30 } 31 template.HTMLEscape(p, line) 32 } 33 } 34 35 type plainText struct{} 36 37 func (plainText) Name() string { 38 return "" 39 } 40 41 func (plainText) Handle(p *Processor, text string) { 42 p.Write([]byte(text)) 43 } 44