func getData(t html.Token, dt html.Token) (ok bool, href string, descr string) { for _, a := range t.Attr { if a.Key == "href" { href = a.Val descr = dt.String() } if a.Key == "class" { if strings.HasPrefix(a.Val, "title may-blank") { ok = true } } } return }
func sanitizeAttributes(u *url.URL, t *html.Token) { var attrs []html.Attribute var isLink = false for _, a := range t.Attr { if a.Key == "target" { } else if a.Key == "style" { a.Val = sanitizeStyle(a.Val) attrs = append(attrs, a) } else if acceptableAttributes[a.Key] { if a.Key == "href" || a.Key == "src" { a.Val = sanitizeLink(u, strings.TrimSpace(a.Val)) } if a.Key == "href" { isLink = true } attrs = append(attrs, a) } } if isLink { attrs = append(attrs, html.Attribute{ Key: "target", Val: "_blank", }) } t.Attr = attrs }
func swapBrackets(token html.Token) string { t := token.String() t = strings.Replace(t, "<", "<", 1) return strings.Replace(t, ">", ">", 1) }