From 1813bb7c39901c028b10798c08f30ed9839acbe3 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 17 May 2019 19:11:17 -0400 Subject: [PATCH] a few more html tags, probably unlikely in AP though --- html.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/html.go b/html.go index 87077a9..0a96ca8 100644 --- a/html.go +++ b/html.go @@ -28,11 +28,14 @@ import ( "golang.org/x/net/html" ) -var permittedtags = []string{"div", "h1", "h2", "h3", "h4", "h5", "h6", - "table", "thead", "tbody", "th", "tr", "td", - "p", "br", "pre", "code", "blockquote", - "strong", "em", "b", "i", "s", "u", "sub", "sup", "del", - "ol", "ul", "li"} +var permittedtags = []string{ + "div", "h1", "h2", "h3", "h4", "h5", "h6", + "table", "thead", "tbody", "th", "tr", "td", "colgroup", "col", + "p", "br", "pre", "code", "blockquote", "q", + "samp", "mark", "ins", "dfn", "cite", "abbr", "address", + "strong", "em", "b", "i", "s", "u", "sub", "sup", "del", "tt", "small", + "ol", "ul", "li", "dl", "dt", "dd", +} var permittedattr = []string{"colspan", "rowspan"} var bannedtags = []string{"script", "style"} @@ -72,8 +75,7 @@ func writetag(w io.Writer, node *html.Node) { } func render(w io.Writer, node *html.Node) { - switch node.Type { - case html.ElementNode: + if node.Type == html.ElementNode { tag := node.Data switch { case tag == "a": @@ -99,12 +101,14 @@ func render(w io.Writer, node *html.Node) { case contains(bannedtags, tag): return } - case html.TextNode: + } else if node.Type == html.TextNode { io.WriteString(w, html.EscapeString(node.Data)) } + for c := node.FirstChild; c != nil; c = c.NextSibling { render(w, c) } + if node.Type == html.ElementNode { tag := node.Data if tag == "a" || (contains(permittedtags, tag) && tag != "br") {