vendor/github.com/russross/blackfriday/esc.go
changeset 246 0998f404dd31
parent 245 910f00ab2799
child 247 1ca743b3eb80
equal deleted inserted replaced
245:910f00ab2799 246:0998f404dd31
     1 package blackfriday
       
     2 
       
     3 import (
       
     4 	"html"
       
     5 	"io"
       
     6 )
       
     7 
       
     8 var htmlEscaper = [256][]byte{
       
     9 	'&': []byte("&"),
       
    10 	'<': []byte("&lt;"),
       
    11 	'>': []byte("&gt;"),
       
    12 	'"': []byte("&quot;"),
       
    13 }
       
    14 
       
    15 func escapeHTML(w io.Writer, s []byte) {
       
    16 	var start, end int
       
    17 	for end < len(s) {
       
    18 		escSeq := htmlEscaper[s[end]]
       
    19 		if escSeq != nil {
       
    20 			w.Write(s[start:end])
       
    21 			w.Write(escSeq)
       
    22 			start = end + 1
       
    23 		}
       
    24 		end++
       
    25 	}
       
    26 	if start < len(s) && end <= len(s) {
       
    27 		w.Write(s[start:end])
       
    28 	}
       
    29 }
       
    30 
       
    31 func escLink(w io.Writer, text []byte) {
       
    32 	unesc := html.UnescapeString(string(text))
       
    33 	escapeHTML(w, []byte(unesc))
       
    34 }