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 { if node.Type == html.TextNode {
data := strings.Trim(node.Data, "\r\n") data := strings.Trim(node.Data, "\r\n")
if data != "" { if data != "" {
w.WriteString(data + "\n") w.WriteString(data)
} }
} }
for c := node.FirstChild; c != nil; c = c.NextSibling { for c := node.FirstChild; c != nil; c = c.NextSibling {
extractText(c, w) extractText(c, w)
} }
if node.Type == html.ElementNode {
name := strings.ToLower(node.Data)
if name == "br" {
w.WriteString("\n")
}
}
} }
extractText(doc, &buf) extractText(doc, &buf)
return buf.String() return buf.String()

View File

@ -5,10 +5,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
"net/url" "net/url"
"os"
"path" "path"
"strings" "strings"
"time" "time"
@ -309,7 +307,7 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
} }
if err == nil { if err == nil {
name := "" name := ""
s := bufio.NewScanner(io.TeeReader(resp.Body, os.Stdout)) s := bufio.NewScanner(resp.Body)
for s.Scan() { for s.Scan() {
line := s.Text() line := s.Text()
token := strings.SplitN(line, ":", 2) token := strings.SplitN(line, ":", 2)