Esempio n. 1
0
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
}
Esempio n. 2
0
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
}
Esempio n. 3
0
func swapBrackets(token html.Token) string {
	t := token.String()
	t = strings.Replace(t, "<", "&lt;", 1)
	return strings.Replace(t, ">", "&gt;", 1)
}