2016-09-10 19:33:37 +08:00
|
|
|
package blackfriday
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2016-10-08 22:58:30 +08:00
|
|
|
var htmlEscaper = [256][]byte{
|
|
|
|
'&': []byte("&"),
|
|
|
|
'<': []byte("<"),
|
|
|
|
'>': []byte(">"),
|
|
|
|
'"': []byte("""),
|
2016-09-10 19:33:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func escapeHTML(w io.Writer, s []byte) {
|
|
|
|
var start, end int
|
|
|
|
for end < len(s) {
|
2016-10-08 22:58:30 +08:00
|
|
|
escSeq := htmlEscaper[s[end]]
|
|
|
|
if escSeq != nil {
|
|
|
|
w.Write(s[start:end])
|
|
|
|
w.Write(escSeq)
|
|
|
|
start = end + 1
|
2016-09-10 19:33:37 +08:00
|
|
|
}
|
|
|
|
end++
|
|
|
|
}
|
|
|
|
if start < len(s) && end <= len(s) {
|
|
|
|
w.Write(s[start:end])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func escLink(w io.Writer, text []byte) {
|
|
|
|
unesc := html.UnescapeString(string(text))
|
|
|
|
escapeHTML(w, []byte(unesc))
|
|
|
|
}
|