forked from alash3al/smtp2http
/
htmlprobe.go
43 lines (36 loc) · 873 Bytes
/
htmlprobe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package telegram
import (
"strings"
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
)
func GetHtmlBodyContent(htmlDoc string) string {
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(htmlDoc))
sel := doc.Find("BODY")
html, _ := sel.Html()
return html
}
func IsHtmlAdaptedForTelegram(text string) bool {
tkn := html.NewTokenizer(strings.NewReader(text))
var acceptedVals []string = []string{"b", "strong", "i", "em", "u", "ins", "s", "strike", "del",
"tg-spoiler", "a", "code", "pre"}
for {
tt := tkn.Next()
if tt == html.ErrorToken {
return true
} else if tt == html.StartTagToken {
t := tkn.Token()
tag := strings.ToLower(t.Data)
unsupported := true
for _, accepted := range acceptedVals {
if tag == accepted {
unsupported = false
break
}
}
if unsupported {
return false
}
}
}
}