diff --git a/http.go b/http.go index fcbb773..00275fa 100644 --- a/http.go +++ b/http.go @@ -126,11 +126,6 @@ func (kf *KF) GetPost(ctx context.Context, postID uint32) (Post, error) { return Post{}, errors.New("Failed to parse post message body.") } - bh, err := body.Html() - if err != nil { - return Post{}, err - } - author, err := parsePostAuthor(article) if err != nil { return Post{}, err @@ -138,8 +133,6 @@ func (kf *KF) GetPost(ctx context.Context, postID uint32) (Post, error) { post := Post{ Author: author, - Text: bytes.TrimSpace([]byte(body.Text())), - HTML: bytes.TrimSpace([]byte(bh)), article: article, body: body, diff --git a/libkiwi.go b/libkiwi.go index 1a61c11..a0ad681 100644 --- a/libkiwi.go +++ b/libkiwi.go @@ -88,19 +88,20 @@ func parsePostAuthor(article *gq.Selection) (User, error) { type Post struct { Author User - Text []byte - - HTML []byte article *gq.Selection body *gq.Selection } -func (post *Post) TextContent() (io.Reader, error) { - postHTML, err := post.body.Html() +func (post *Post) TextContent() io.Reader { + return strings.NewReader(strings.TrimSpace(post.body.Text())) +} + +func (post *Post) HTML() (io.Reader, error) { + postHTML, err := post.article.Html() if err != nil { return nil, err } - return strings.NewReader(postHTML), nil + return strings.NewReader(strings.TrimSpace(postHTML)), nil } diff --git a/libkiwi_test.go b/libkiwi_test.go index bd6b725..0123b28 100644 --- a/libkiwi_test.go +++ b/libkiwi_test.go @@ -55,6 +55,7 @@ func TestGetPost(t *testing.T) { } t.Logf("Post author: %+v\n", post.Author) + t.Logf("Post text: %s\n", post.TextContent()) } func newTestKF() (*KF, error) { diff --git a/utils.go b/utils.go index 5ce75e7..244903c 100644 --- a/utils.go +++ b/utils.go @@ -1,7 +1,6 @@ package libkiwi import ( - "bufio" "context" "fmt" "io"