-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.go
56 lines (45 loc) · 1.73 KB
/
func.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
44
45
46
47
48
49
50
51
52
53
54
55
56
package htmlValidator
import (
"io"
"strings"
)
/* Приведение html-текста к "стандартному" виду */
func Standardization(htmlText io.Reader) string {
transformObj := TextTransform()
transformObj.AddParagraph("<"+TagParagraph+">", "</"+TagParagraph+">")
transformObj.AddParagraphLeft("<"+TagParagraph+" "+AttrLeft+">", "</"+TagParagraph+">")
transformObj.AddParagraphRight("<"+TagParagraph+" "+AttrRight+">", "</"+TagParagraph+">")
transformObj.AddParagraphCenter("<"+TagParagraph+" "+AttrCenter+">", "</"+TagParagraph+">")
transformObj.AddDelimiter("<" + TagDelimiter + ">")
transformObj.AddTagBold("<"+TagBold+">", "</"+TagBold+">")
transformObj.AddTagItalic("<"+TagItalic+">", "</"+TagItalic+">")
transformObj.AddTagUnderline("<"+TagUnderline+">", "</"+TagUnderline+">")
transformObj.AddTagLineThrough("<"+TagLineThrough+">", "</"+TagLineThrough+">")
transformObj.AddTagQuote("<"+TagQuote+">", "</"+TagQuote+">")
transformObj.AddTagSubScript("<"+TagSubScript+">", "</"+TagSubScript+">")
transformObj.AddTagSuperScript("<"+TagSuperScript+">", "</"+TagSuperScript+">")
return transformObj.Transform(htmlText)
}
/* Возращает только текст */
func Text(htmlText io.Reader) string {
transformObj := TextTransform()
return transformObj.Transform(htmlText)
}
/* Возрашвет только текст и БЫСТРО */
func TextFast(htmlText io.Reader) string {
buf := new(strings.Builder)
io.Copy(buf, htmlText)
input := buf.String()
output := make([]rune, 0, len(input))
inTag := false
for _, char := range input {
if char == '<' {
inTag = true
} else if char == '>' {
inTag = false
} else if !inTag {
output = append(output, char)
}
}
return string(output)
}