コード例 #1
0
func Blacklist(w io.Writer, n *html.Node, filterItems []htmlrender.MinimalHtmlNode) error {

	// returns false if there is ANY  100% match between the node any MinimumHTMLNode
	renderDecisionFunc := func(n html.Node, filterItems []htmlrender.MinimalHtmlNode) bool {
		for _, minNode := range filterItems {
			if htmlrender.TagMatch(n, minNode) && htmlrender.AttributeMatch(n.Attr, minNode.Attr) {
				return false
			}
		}
		return true
	}

	err := htmlrender.RenderSans(w, n, renderDecisionFunc, filterItems)

	if err != nil {
		return err
	}
	return nil
}
コード例 #2
0
func Whitelist(w io.Writer, n *html.Node, filterItems []htmlrender.MinimalHtmlNode) error {

	for _, minNode := range filterItems {
		nodeCopy := html.Node{
			Data: n.Data,
			Attr: n.Attr,
		}
		if htmlrender.TagMatch(nodeCopy, minNode) && htmlrender.AttributeMatch(n.Attr, minNode.Attr) {
			err := html.Render(w, n)

			if err != nil {
				return err
			}
		}
	}

	for c := n.FirstChild; c != nil; c = c.NextSibling {
		Whitelist(w, c, filterItems)
	}

	return nil
}