2018-01-25 21:01:19 +00:00
|
|
|
package markdown
|
2016-09-10 11:33:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"html"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2016-10-08 14:58:30 +00:00
|
|
|
var htmlEscaper = [256][]byte{
|
|
|
|
'&': []byte("&"),
|
|
|
|
'<': []byte("<"),
|
|
|
|
'>': []byte(">"),
|
|
|
|
'"': []byte("""),
|
2016-09-10 11:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func escapeHTML(w io.Writer, s []byte) {
|
|
|
|
var start, end int
|
|
|
|
for end < len(s) {
|
2016-10-08 14:58:30 +00:00
|
|
|
escSeq := htmlEscaper[s[end]]
|
|
|
|
if escSeq != nil {
|
|
|
|
w.Write(s[start:end])
|
|
|
|
w.Write(escSeq)
|
|
|
|
start = end + 1
|
2016-09-10 11:33:37 +00: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))
|
|
|
|
}
|