escape html strings

pull/23/head
ericchiang 10 years ago
parent 377f8f1b77
commit 40f7f533c4

@ -37,7 +37,8 @@ func (a AttrDisplayer) Display(nodes []*html.Node) {
attributes := node.Attr
for _, attr := range attributes {
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) {
switch n.Type {
case html.TextNode:
s := n.Data
s := html.EscapeString(n.Data)
if !whitespaceRegexp.MatchString(s) {
s = preWhitespace.ReplaceAllString(s, "")
s = postWhitespace.ReplaceAllString(s, "")
@ -94,9 +94,11 @@ func (t TreeDisplayer) printNode(n *html.Node, level int) {
fmt.Print(" ")
attrKeyColor.Printf("%s", a.Key)
tokenColor.Print("=")
quoteColor.Printf(`"%s"`, a.Val)
val := html.EscapeString(a.Val)
quoteColor.Printf(`"%s"`, val)
} else {
fmt.Printf(` %s="%s"`, a.Key, a.Val)
val := html.EscapeString(a.Val)
fmt.Printf(` %s="%s"`, a.Key, val)
}
}
if printColor {

Loading…
Cancel
Save