~ecs/hq

ref: 05e89aaebceb0242aaa43c75277e0b2cc05a11a0 hq/totext.go -rw-r--r-- 516 bytes
05e89aaeEmber Sawady Improve multi error handling 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"github.com/jaytaylor/html2text"
)

type totext struct{}

func (totext) Execute(args []string, ins []<-chan Datum, out chan Datum) error {
	defer func() {
		out <- Datum{End: true}
		close(out)
	}()
	for _, d := Select(ins); d != nil; _, d = Select(ins) {
		if d.Text != nil {
			out <- *d
		}
		if d.HTML != nil {
			s, err := html2text.FromHTMLNode(d.HTML)
			if err != nil {
				return err
			}
			out <- Datum{Text: &s}
		}
	}
	return nil
}

func init() {
	Filters["totext"] = totext{}
}