Ejemplo n.º 1
0
func (t *Transformer) ApplyToFirstMatch(f TransformFunc, sels ...string) error {
	cs := make([]Collector, 0, len(sels))
	for _, sel := range sels {
		sq, err := selector.Selector(sel)
		if err != nil {
			return err
		}
		cs = append(cs, sq)
	}
	t.ApplyWithCollector(f, FirstMatch(cs...))
	return nil
}
Ejemplo n.º 2
0
// SubTransform constructs a TransformFunc that runs a TransformFunc on
// any nodes in the tree rooted by the node the the TransformFunc is run
// against.
// This is useful for creating self contained Transforms that are
// meant to work on subtrees of the html document.
func Subtransform(f TransformFunc, sel string) (TransformFunc, error) {
	sq, err := selector.Selector(sel)
	return SubtransformCollector(f, sq), err
}
Ejemplo n.º 3
0
// The ApplyWithSelector method applies a TransformFunc to the nodes matched
// by the CSS3 Selector.
func (t *Transformer) Apply(f TransformFunc, sel string) error {
	sq, err := selector.Selector(sel)
	t.ApplyWithCollector(f, sq)
	return err
}
Ejemplo n.º 4
0
// Trans creates a Transform that you can apply using ApplyAll.
// It takes a TransformFunc and a valid CSS3 Selector.
// It returns a *Transform or an error if the selector wasn't valid
func Trans(f TransformFunc, sel string) (*Transform, error) {
	sq, err := selector.Selector(sel)
	return TransCollector(f, sq), err
}