htmltools

Various command line tools to transform HTML documents
git clone git://git.entf.net/htmltools
Log | Files | Refs | README | LICENSE

commit 39f445d0b67c3b736ce6d2e88c47c5dcaa077941
parent 710f03271e34157d1d7575cd3b3a172d243b4781
Author: Lukas Henkel <lh@entf.net>
Date:   Mon, 17 Aug 2020 18:33:07 +0200

Write selected html nodes on seperate lines

Diffstat:
Mhtmlselect/main.go | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/htmlselect/main.go b/htmlselect/main.go @@ -1,8 +1,10 @@ package main // import "entf.net/htmltools/htmlselect" import ( + "bytes" "fmt" "os" + "strings" "github.com/andybalholm/cascadia" "golang.org/x/net/html" @@ -28,6 +30,11 @@ func main() { func dosel(sel cascadia.Selector, doc *html.Node) { for _, n := range sel.MatchAll(doc) { - html.Render(os.Stdout, n) + buf := &bytes.Buffer{} + html.Render(buf, n) + l := buf.String() + l = strings.ReplaceAll(l, "\n", " ") + l = strings.TrimSpace(l) + fmt.Println(l) } }