mirror of
https://github.com/ericchiang/pup
synced 2024-11-24 08:58:08 +00:00
escape html strings
This commit is contained in:
parent
377f8f1b77
commit
40f7f533c4
@ -37,7 +37,8 @@ func (a AttrDisplayer) Display(nodes []*html.Node) {
|
|||||||
attributes := node.Attr
|
attributes := node.Attr
|
||||||
for _, attr := range attributes {
|
for _, attr := range attributes {
|
||||||
if attr.Key == a.Attr {
|
if attr.Key == a.Attr {
|
||||||
fmt.Println(attr.Val)
|
val := html.EscapeString(attr.Val)
|
||||||
|
fmt.Printf("%s\n", val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (t TreeDisplayer) printIndent(level int) {
|
|||||||
func (t TreeDisplayer) printNode(n *html.Node, level int) {
|
func (t TreeDisplayer) printNode(n *html.Node, level int) {
|
||||||
switch n.Type {
|
switch n.Type {
|
||||||
case html.TextNode:
|
case html.TextNode:
|
||||||
s := n.Data
|
s := html.EscapeString(n.Data)
|
||||||
if !whitespaceRegexp.MatchString(s) {
|
if !whitespaceRegexp.MatchString(s) {
|
||||||
s = preWhitespace.ReplaceAllString(s, "")
|
s = preWhitespace.ReplaceAllString(s, "")
|
||||||
s = postWhitespace.ReplaceAllString(s, "")
|
s = postWhitespace.ReplaceAllString(s, "")
|
||||||
@ -94,9 +94,11 @@ func (t TreeDisplayer) printNode(n *html.Node, level int) {
|
|||||||
fmt.Print(" ")
|
fmt.Print(" ")
|
||||||
attrKeyColor.Printf("%s", a.Key)
|
attrKeyColor.Printf("%s", a.Key)
|
||||||
tokenColor.Print("=")
|
tokenColor.Print("=")
|
||||||
quoteColor.Printf(`"%s"`, a.Val)
|
val := html.EscapeString(a.Val)
|
||||||
|
quoteColor.Printf(`"%s"`, val)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(` %s="%s"`, a.Key, a.Val)
|
val := html.EscapeString(a.Val)
|
||||||
|
fmt.Printf(` %s="%s"`, a.Key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if printColor {
|
if printColor {
|
||||||
|
Loading…
Reference in New Issue
Block a user