forked from JohannesKaufmann/html-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_node.go
43 lines (36 loc) · 1.36 KB
/
is_node.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 collapse
import (
"github.com/JohannesKaufmann/dom"
"golang.org/x/net/html"
)
var blockElements = []string{
"address", "article", "aside", "audio", "blockquote", "body", "canvas", "center", "dd", "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "html", "isindex", "li", "main", "menu", "nav", "noframes", "noscript", "ol", "output", "p", "pre", "section", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "ul",
}
var voidElements = []string{
// Note: Compared to the javascript implementation, I removed "source"
"area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param" /* "source, "*/, "track", "wbr",
}
var defaultIsBlockNode = func(node *html.Node) bool {
name := dom.NodeName(node)
for _, elem := range blockElements {
if elem == name {
return true
}
}
return false
}
var defaultIsVoidNode = func(node *html.Node) bool {
name := dom.NodeName(node)
for _, elem := range voidElements {
if elem == name {
return true
}
}
return false
}
var defaultIsPreformattedNode = func(node *html.Node) bool {
// Note: Originally in the javascript version, this just checked for "pre".
// I changed it, to also return true for "code"
name := dom.NodeName(node)
return name == "pre" || name == "code"
}