Skip to content

Commit

Permalink
lobsters: switch to use the plaintext field
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed May 5, 2023
1 parent 3a3b45b commit 8bafc3a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions internal/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func FormatHtml2Text(htmlText string, width, leftPadding int) string {
return wrapped
}

func FormatText(plainText string, width, leftPadding int) string {
wrapped, _ := text.WrapLeftPadded(
GreenTextIt(strings.ReplaceAll(plainText, "\r\n", "\n")),
width,
leftPadding,
)
return wrapped
}

func Min(a, b int) int {
if a < b {
return a
Expand Down
4 changes: 2 additions & 2 deletions internal/lobsters/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Fetch(rawUrl, userAgent string, timeout time.Duration) (*Thread, error) {
thread := Thread{}
thread.op = Op{
createdAt: gjson.Get(jsonRaw, "created_at").Time(),
message: gjson.Get(jsonRaw, "description").String(),
message: gjson.Get(jsonRaw, "description_plain").String(),
nComments: int(gjson.Get(jsonRaw, "comment_count").Int()),
score: int(gjson.Get(jsonRaw, "score").Int()),
self: rawUrl,
Expand All @@ -41,7 +41,7 @@ func Fetch(rawUrl, userAgent string, timeout time.Duration) (*Thread, error) {
thread.insert(Comment{
createdAt: comment.Get("created_at").Time(),
id: comment.Get("short_id").String(),
message: comment.Get("comment").String(),
message: comment.Get("comment_plain").String(),
parent: comment.Get("parent_comment").String(),
score: int(comment.Get("score").Int()),
thread: &thread,
Expand Down
4 changes: 2 additions & 2 deletions internal/lobsters/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (o Op) String() (ret string) {
}
ret += fmt.Sprintf(
"\n%s\n\n",
format.FormatHtml2Text(o.message, o.thread.LineWidth, o.thread.LeftPadding),
format.FormatText(o.message, o.thread.LineWidth, o.thread.LeftPadding),
)
ret += fmt.Sprintf(
"%s - %s \n\n\n",
Expand All @@ -45,7 +45,7 @@ func (c Comment) String() (ret string) {
) - rightPadding
ret += fmt.Sprintf(
"%s\n",
format.FormatHtml2Text(c.message, lineWidth, leftPadding+extraLeft),
format.FormatText(c.message, lineWidth, leftPadding+extraLeft),
)
ret += strings.Repeat(" ", leftPadding)
ret += ">>"
Expand Down

0 comments on commit 8bafc3a

Please sign in to comment.