fix text breaking by lines

pull/5/head
Yasuhiro Matsumoto 2017-04-14 13:53:56 +09:00
parent a4d83d3b95
commit 2b246d789d
2 changed files with 8 additions and 4 deletions

View File

@ -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()

View File

@ -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)