256
|
1 |
package blackfriday |
|
2 |
|
|
3 |
import ( |
|
4 |
"html" |
|
5 |
"io" |
|
6 |
) |
|
7 |
|
|
8 |
var htmlEscaper = [256][]byte{ |
|
9 |
'&': []byte("&"), |
|
10 |
'<': []byte("<"), |
|
11 |
'>': []byte(">"), |
|
12 |
'"': []byte("""), |
|
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 |
} |