Debian Codegraph @

display.go

raw symbols SCIP
1 package mainscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/
2
3 import (
4 "encoding/jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/"
5 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
6 "regexpscip-go gomod github.com/golang/go/src go1.13 regexp/"
7 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
8
9 "github.com/fatih/colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/"
10 colorablescip-go gomod github.com/mattn/go-colorable v0.0.5 `github.com/mattn/go-colorable`/ "github.com/mattn/go-colorablescip-go gomod github.com/mattn/go-colorable v0.0.5 `github.com/mattn/go-colorable`/"
11 "golang.org/x/net/htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/"
12 "golang.org/x/net/html/atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/"
13 )
14
15 func initscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/init().() {
16 colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Outputscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Output. = colorablescip-go gomod github.com/mattn/go-colorable v0.0.5 `github.com/mattn/go-colorable`/.NewColorableStdoutscip-go gomod github.com/mattn/go-colorable v0.0.5 `github.com/mattn/go-colorable`/NewColorableStdout().()
17 }
18
19 type Displayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/Displayer# interface {
20 Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/Displayer#Display.([]*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#)
21 }
22
23 func ParseDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/ParseDisplayer().(cmd string) error {
24 attrRe := regexpscip-go gomod github.com/golang/go/src go1.13 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.13 regexp/MustCompile().(`attr\{([a-zA-Z\-]+)\}`)
25 if cmd == "text{}" {
26 pupDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupDisplayer. = TextDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TextDisplayer#{}
27 } else if cmd == "json{}" {
28 pupDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupDisplayer. = JSONDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/JSONDisplayer#{}
29 } else if match := attrRe.FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.13 regexp/Regexp#FindAllStringSubmatch().(cmd, -1); len(match) == 1 {
30 pupDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupDisplayer. = AttrDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#{
31 Attrscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#Attr.: match[0][1],
32 }
33 } else {
34 return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unknown displayer")
35 }
36 return nil
37 }
38
39 // Is this node a tag with no end tag such as <meta> or <br>?
40 // http://www.w3.org/TR/html-markup/syntax.html#syntax-elements
41 func isVoidElementscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/isVoidElement().(n *htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) bool {
42 switch n.DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. {
43 case atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Areascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Area., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Basescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Base., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Brscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Br., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Colscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Col., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Commandscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Command., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Embedscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Embed.,
44 atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Hrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Hr., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Imgscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Img., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Inputscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Input., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Keygenscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Keygen., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Linkscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Link.,
45 atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Metascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Meta., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Paramscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Param., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Sourcescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Source., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Trackscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Track., atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Wbrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Wbr.:
46 return true
47 }
48 return false
49 }
50
51 var (
52 // Colors
53 tagColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tagColor. *colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color# = colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Newscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/New().(colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.FgCyanscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/FgCyan.)
54 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor. = colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Newscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/New().(colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.FgCyanscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/FgCyan.)
55 attrKeyColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/attrKeyColor. = colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Newscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/New().(colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.FgMagentascip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/FgMagenta.)
56 quoteColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/quoteColor. = colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Newscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/New().(colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.FgBluescip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/FgBlue.)
57 commentColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/commentColor. = colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.Newscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/New().(colorscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/.FgYellowscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/FgYellow.)
58 )
59
60 type TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer# struct {
61 }
62
63 func (t TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#) Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#Display().(nodes []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
64 for _, node := range nodes {
65 t.printNodescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printNode().(node, 0)
66 }
67 }
68
69 // The <pre> tag indicates that the text within it should always be formatted
70 // as is. See https://github.com/ericchiang/pup/issues/33
71 func (t TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#) printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(n *htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
72 switch n.Typescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Type. {
73 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.TextNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/TextNode.:
74 s := n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.
75 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
76 // don't escape javascript
77 if n.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent. == nil || n.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent..DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. != atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Scriptscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Script. {
78 s = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(s)
79 }
80 }
81 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printscip-go gomod github.com/golang/go/src go1.13 fmt/Print().(s)
82 for c := n.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.; c != nil; c = c.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling. {
83 t.printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(c)
84 }
85 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.ElementNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/ElementNode.:
86 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("<%s", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
87 for _, a := range n.Attrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Attr. {
88 val := a.Valscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Val.
89 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
90 val = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(val)
91 }
92 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().(` %s="%s"`, a.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key., val)
93 }
94 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printscip-go gomod github.com/golang/go/src go1.13 fmt/Print().(">")
95 if !isVoidElementscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/isVoidElement().(n) {
96 for c := n.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.; c != nil; c = c.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling. {
97 t.printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(c)
98 }
99 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("</%s>", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
100 }
101 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.CommentNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/CommentNode.:
102 data := n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.
103 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
104 data = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(data)
105 }
106 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("<!--%s-->\n", data)
107 for c := n.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.; c != nil; c = c.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling. {
108 t.printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(c)
109 }
110 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.DoctypeNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/DoctypeNode., htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.DocumentNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/DocumentNode.:
111 for c := n.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.; c != nil; c = c.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling. {
112 t.printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(c)
113 }
114 }
115 }
116
117 // Print a node and all of it's children to `maxlevel`.
118 func (t TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#) printNodescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printNode().(n *htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#, level int) {
119 switch n.Typescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Type. {
120 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.TextNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/TextNode.:
121 s := n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.
122 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
123 // don't escape javascript
124 if n.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent. == nil || n.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent..DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. != atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Scriptscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Script. {
125 s = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(s)
126 }
127 }
128 s = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.13 strings/TrimSpace().(s)
129 if s != "" {
130 t.printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level)
131 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().(s)
132 }
133 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.ElementNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/ElementNode.:
134 t.printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level)
135 // TODO: allow pre with color
136 if n.DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. == atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Prescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Pre. && !pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. && pupPreformattedscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPreformatted. {
137 t.printPrescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printPre().(n)
138 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().()
139 return
140 }
141 if pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. {
142 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor..Printscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Print().("<")
143 tagColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tagColor..Printfscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Printf().("%s", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
144 } else {
145 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("<%s", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
146 }
147 for _, a := range n.Attrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Attr. {
148 val := a.Valscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Val.
149 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
150 val = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(val)
151 }
152 if pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. {
153 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printscip-go gomod github.com/golang/go/src go1.13 fmt/Print().(" ")
154 attrKeyColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/attrKeyColor..Printfscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Printf().("%s", a.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key.)
155 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor..Printscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Print().("=")
156 quoteColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/quoteColor..Printfscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Printf().(`"%s"`, val)
157 } else {
158 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().(` %s="%s"`, a.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key., val)
159 }
160 }
161 if pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. {
162 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor..Printlnscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Println().(">")
163 } else {
164 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().(">")
165 }
166 if !isVoidElementscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/isVoidElement().(n) {
167 t.printChildrenscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printChildren().(n, level+1)
168 t.printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level)
169 if pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. {
170 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor..Printscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Print().("</")
171 tagColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tagColor..Printfscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Printf().("%s", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
172 tokenColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/tokenColor..Printlnscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Println().(">")
173 } else {
174 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("</%s>\n", n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
175 }
176 }
177 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.CommentNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/CommentNode.:
178 t.printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level)
179 data := n.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.
180 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
181 data = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(data)
182 }
183 if pupPrintColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupPrintColor. {
184 commentColorscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/commentColor..Printfscip-go gomod github.com/fatih/color v1.0.0 `github.com/fatih/color`/Color#Printf().("<!--%s-->\n", data)
185 } else {
186 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("<!--%s-->\n", data)
187 }
188 t.printChildrenscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printChildren().(n, level)
189 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.DoctypeNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/DoctypeNode., htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.DocumentNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/DocumentNode.:
190 t.printChildrenscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printChildren().(n, level)
191 }
192 }
193
194 func (t TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#) printChildrenscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printChildren().(n *htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#, level int) {
195 if pupMaxPrintLevelscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupMaxPrintLevel. > -1 {
196 if level >= pupMaxPrintLevelscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupMaxPrintLevel. {
197 t.printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level)
198 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().("...")
199 return
200 }
201 }
202 child := n.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.
203 for child != nil {
204 t.printNodescip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printNode().(child, level)
205 child = child.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling.
206 }
207 }
208
209 func (t TreeDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#) printIndentscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TreeDisplayer#printIndent().(level int) {
210 for ; level > 0; level-- {
211 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printscip-go gomod github.com/golang/go/src go1.13 fmt/Print().(pupIndentStringscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupIndentString.)
212 }
213 }
214
215 // Print the text of a node
216 type TextDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TextDisplayer# struct{}
217
218 func (t TextDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TextDisplayer#) Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TextDisplayer#Display().(nodes []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
219 for _, node := range nodes {
220 if node.Typescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Type. == htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.TextNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/TextNode. {
221 data := node.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.
222 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
223 // don't escape javascript
224 if node.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent. == nil || node.Parentscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Parent..DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. != atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Scriptscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Script. {
225 data = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(data)
226 }
227 }
228 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().(data)
229 }
230 children := []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#{}
231 child := node.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.
232 for child != nil {
233 children = append(children, child)
234 child = child.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling.
235 }
236 t.Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/TextDisplayer#Display().(children)
237 }
238 }
239
240 // Print the attribute of a node
241 type AttrDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer# struct {
242 Attrscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#Attr. string
243 }
244
245 func (a AttrDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#) Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#Display().(nodes []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
246 for _, node := range nodes {
247 attributes := node.Attrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Attr.
248 for _, attr := range attributes {
249 if attr.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key. == a.Attrscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/AttrDisplayer#Attr. {
250 val := attr.Valscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Val.
251 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
252 val = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(val)
253 }
254 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("%s\n", val)
255 }
256 }
257 }
258 }
259
260 // Print nodes as a JSON list
261 type JSONDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/JSONDisplayer# struct{}
262
263 // returns a jsonifiable struct
264 func jsonifyscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/jsonify().(node *htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) map[string]interface{} {
265 vals := map[string]interface{}{}
266 if len(node.Attrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Attr.) > 0 {
267 for _, attr := range node.Attrscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Attr. {
268 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
269 vals[attr.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key.] = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(attr.Valscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Val.)
270 } else {
271 vals[attr.Keyscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Key.] = attr.Valscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Attribute#Val.
272 }
273 }
274 }
275 vals["tag"] = node.DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom..Stringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Atom#String().()
276 children := []interface{}{}
277 for child := node.FirstChildscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#FirstChild.; child != nil; child = child.NextSiblingscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#NextSibling. {
278 switch child.Typescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Type. {
279 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.ElementNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/ElementNode.:
280 children = append(children, jsonifyscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/jsonify().(child))
281 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.TextNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/TextNode.:
282 text := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.13 strings/TrimSpace().(child.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
283 if text != "" {
284 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
285 // don't escape javascript
286 if node.DataAtomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#DataAtom. != atomscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/.Scriptscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html/atom`/Script. {
287 text = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(text)
288 }
289 }
290 // if there is already text we'll append it
291 currText, ok := vals["text"]
292 if ok {
293 text = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s %s", currText, text)
294 }
295 vals["text"] = text
296 }
297 case htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.CommentNodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/CommentNode.:
298 comment := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.13 strings/TrimSpace().(child.Datascip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#Data.)
299 if pupEscapeHTMLscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupEscapeHTML. {
300 comment = htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.EscapeStringscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/EscapeString().(comment)
301 }
302 currComment, ok := vals["comment"]
303 if ok {
304 comment = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s %s", currComment, comment)
305 }
306 vals["comment"] = comment
307 }
308 }
309 if len(children) > 0 {
310 vals["children"] = children
311 }
312 return vals
313 }
314
315 func (j JSONDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/JSONDisplayer#) Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/JSONDisplayer#Display().(nodes []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
316 var data []byte
317 var err error
318 jsonNodes := []map[string]interface{}{}
319 for _, node := range nodes {
320 jsonNodes = append(jsonNodes, jsonifyscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/jsonify().(node))
321 }
322 data, err = jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/MarshalIndent().(&jsonNodes, "", pupIndentStringscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/pupIndentString.)
323 if err != nil {
324 panic("Could not jsonify nodes")
325 }
326 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printfscip-go gomod github.com/golang/go/src go1.13 fmt/Printf().("%s\n", data)
327 }
328
329 // Print the number of features returned
330 type NumDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/NumDisplayer# struct{}
331
332 func (d NumDisplayerscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/NumDisplayer#) Displayscip-go gomod github.com/ericchiang/pup . `github.com/ericchiang/pup`/NumDisplayer#Display().(nodes []*htmlscip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/.Nodescip-go gomod golang.org/x/net 4d38db76854b `golang.org/x/net/html`/Node#) {
333 fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.13 fmt/Println().(len(nodes))
334 }