fix text breaking by lines
parent
a4d83d3b95
commit
2b246d789d
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue