From 2b246d789deaf12792c324f5dd9b375ea320189c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 14 Apr 2017 13:53:56 +0900 Subject: [PATCH] fix text breaking by lines --- cmd/mstdn/main.go | 8 +++++++- mastodon.go | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index c6906de..5ba655f 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -46,12 +46,18 @@ func textContent(s string) string { if node.Type == html.TextNode { data := strings.Trim(node.Data, "\r\n") if data != "" { - w.WriteString(data + "\n") + w.WriteString(data) } } for c := node.FirstChild; c != nil; c = c.NextSibling { extractText(c, w) } + if node.Type == html.ElementNode { + name := strings.ToLower(node.Data) + if name == "br" { + w.WriteString("\n") + } + } } extractText(doc, &buf) return buf.String() diff --git a/mastodon.go b/mastodon.go index 163777f..f44cfb2 100644 --- a/mastodon.go +++ b/mastodon.go @@ -5,10 +5,8 @@ import ( "context" "encoding/json" "fmt" - "io" "net/http" "net/url" - "os" "path" "strings" "time" @@ -309,7 +307,7 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) { } if err == nil { name := "" - s := bufio.NewScanner(io.TeeReader(resp.Body, os.Stdout)) + s := bufio.NewScanner(resp.Body) for s.Scan() { line := s.Text() token := strings.SplitN(line, ":", 2)