package main
import (
"errors"
"golang.org/x/net/html"
)
type root struct{}
func (root) Execute(args []string, ins []<-chan Datum, out chan Datum) error {
defer func() {
out <- Datum{End: true}
close(out)
}()
if len(args) != 1 {
return errors.New("usage: root")
}
for _, d := Select(ins); d != nil; _, d = Select(ins) {
if d.End {
continue
}
if d.HTML == nil {
return errors.New("type error: expected html, got text")
}
for c := d.HTML.FirstChild; c != nil; {
next := c.NextSibling
if c.Type == html.ElementNode {
d.HTML.RemoveChild(c)
}
c = next
}
out <- Datum{HTML: d.HTML}
}
return nil
}
func init() {
Filters["root"] = root{}
}