all repos — grayfriday @ 919b1f5b9bfe13933b93762ee39ea97de79039d9

blackfriday fork with a few changes

esc.go (view raw)

 1package blackfriday
 2
 3import (
 4	"html"
 5	"io"
 6)
 7
 8var htmlEscaper = [256][]byte{
 9	'&': []byte("&"),
10	'<': []byte("&lt;"),
11	'>': []byte("&gt;"),
12	'"': []byte("&quot;"),
13}
14
15func 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
31func escLink(w io.Writer, text []byte) {
32	unesc := html.UnescapeString(string(text))
33	escapeHTML(w, []byte(unesc))
34}