123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package com
- import (
- "html"
- "regexp"
- "strings"
- )
- func Html2JS(data []byte) []byte {
- s := string(data)
- s = strings.Replace(s, `\`, `\\`, -1)
- s = strings.Replace(s, "\n", `\n`, -1)
- s = strings.Replace(s, "\r", "", -1)
- s = strings.Replace(s, "\"", `\"`, -1)
- s = strings.Replace(s, "<table>", "<table>", -1)
- return []byte(s)
- }
- func HtmlEncode(str string) string {
- return html.EscapeString(str)
- }
- func HtmlDecode(str string) string {
- return html.UnescapeString(str)
- }
- func StripTags(src string) string {
-
- re := regexp.MustCompile(`(?s)<(?:style|script)[^<>]*>.*?</(?:style|script)>|</?[a-z][a-z0-9]*[^<>]*>|<!--.*?-->`)
- src = re.ReplaceAllString(src, "")
-
- re = regexp.MustCompile(`\s{2,}`)
- src = re.ReplaceAllString(src, "\n")
- return strings.TrimSpace(src)
- }
- func Nl2br(str string) string {
- return strings.Replace(str, "\n", "<br/>", -1)
- }
|