diff --git a/funcs/display.go b/funcs/display.go index a014bf8..f168425 100644 --- a/funcs/display.go +++ b/funcs/display.go @@ -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) } } } diff --git a/printing.go b/printing.go index 51880a9..54faef9 100644 --- a/printing.go +++ b/printing.go @@ -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 {