File: is_node.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (2)
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"
}