-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhtml.go
More file actions
78 lines (70 loc) · 1.23 KB
/
html.go
File metadata and controls
78 lines (70 loc) · 1.23 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import "unicode"
var inlineTag = map[string]struct{}{
"a": {},
"i": {},
"u": {},
"b": {},
"br": {},
"tt": {},
"em": {},
"img": {},
"font": {},
"textarea": {},
"input": {},
"strike": {},
"strong": {},
"mark": {},
"label": {},
"span": {},
"ins": {},
"del": {},
"small": {},
"big": {},
"sub": {},
"sup": {},
}
var openOnceTag = map[string]struct{}{
"html": {},
"body": {},
"head": {},
"meta": {},
"main": {},
"nav": {},
"style": {},
"script": {},
}
// Tags that do not have />, but just >
var autoCloseTag = map[string]struct{}{
"base": {},
"meta": {},
"link": {},
}
// htmlTag takes an HTML elements and returns the tag.
func htmlTag(s string) (s1 string) {
for _, r := range s {
if r == '<' || r == '>' || r == '/' {
continue
}
if unicode.IsSpace(r) {
break
}
s1 += string(r)
}
return s1
}
func isInLineTag(s string) bool {
tag := htmlTag(s)
_, ok := inlineTag[tag]
return ok
}
func isOpenOnceTag(s string) bool {
tag := htmlTag(s)
_, ok := openOnceTag[tag]
return ok
}
func isAutoCloseTag(s string) bool {
tag := htmlTag(s)
_, ok := autoCloseTag[tag]
return ok
}