Платформа ЦРНП "Мирокод" для разработки проектов
https://git.mirocod.ru
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
569 B
34 lines
569 B
package blackfriday |
|
|
|
import ( |
|
"html" |
|
"io" |
|
) |
|
|
|
var htmlEscaper = [256][]byte{ |
|
'&': []byte("&"), |
|
'<': []byte("<"), |
|
'>': []byte(">"), |
|
'"': []byte("""), |
|
} |
|
|
|
func escapeHTML(w io.Writer, s []byte) { |
|
var start, end int |
|
for end < len(s) { |
|
escSeq := htmlEscaper[s[end]] |
|
if escSeq != nil { |
|
w.Write(s[start:end]) |
|
w.Write(escSeq) |
|
start = end + 1 |
|
} |
|
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)) |
|
}
|
|
|