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 12 // PlainText is a text processor that just outputs all text with no change. 13 PlainText plainText 14 ) 15 16 type htmlText struct{} 17 18 var ( 19 newLine = []byte{'\n'} 20 newLineHTML = []byte{'<', 'b', 'r', ' ', '/', '>'} 21 ) 22 23 func (htmlText) Name() string { 24 return "" 25 } 26 27 func (htmlText) Handle(p *Processor, text string) { 28 for n, line := range bytes.Split([]byte(text), newLine) { 29 if n > 0 { 30 p.Write(newLineHTML) 31 } 32 33 template.HTMLEscape(p, line) 34 } 35 } 36 37 type plainText struct{} 38 39 func (plainText) Name() string { 40 return "" 41 } 42 43 func (plainText) Handle(p *Processor, text string) { 44 p.Write([]byte(text)) 45 } 46