Skip to content

Commit 06efaf9

Browse files
committed
Use markdown renderer
1 parent 9186df7 commit 06efaf9

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

Gopkg.lock

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,26 @@
2525
# unused-packages = true
2626

2727

28+
[[constraint]]
29+
name = "github.com/gdamore/tcell"
30+
version = "1.1.1"
31+
2832
[[constraint]]
2933
name = "github.com/mitchellh/go-homedir"
3034
version = "1.0.0"
3135

36+
[[constraint]]
37+
branch = "master"
38+
name = "github.com/rivo/tview"
39+
40+
[[constraint]]
41+
name = "github.com/russross/blackfriday"
42+
version = "2.0.1"
43+
44+
[[constraint]]
45+
name = "github.com/scriptonist/termd"
46+
version = "0.0.3"
47+
3248
[[constraint]]
3349
name = "github.com/spf13/cobra"
3450
version = "0.0.3"

pkg/posts/post.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
"github.com/gdamore/tcell"
99
"github.com/rivo/tview"
10+
blackfriday "github.com/russross/blackfriday"
11+
"github.com/scriptonist/termd/pkg/console"
1012
)
1113

1214
// openPost opens a post in a new tview box
@@ -52,16 +54,21 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
5254
ptype,
5355
link,
5456
"\n",
55-
singlePost.Post.ContentMarkdown,
56-
"\n[green]Responses[white]",
57-
"[green]==========[white]",
57+
renderTerminal(singlePost.Post.ContentMarkdown),
58+
func() string {
59+
if len(singlePost.Post.Responses) > 0 {
60+
return fmt.Sprintf("\n%s\n%s\n", "[green]Responses[white]",
61+
"[green]==========[white]")
62+
}
63+
return ""
64+
}(),
5865
)
5966
for ind, response := range singlePost.Post.Responses {
6067
writeToTextView(
6168
textView,
6269
fmt.Sprintf("\n%d", ind+1),
6370
fmt.Sprintf("---"),
64-
response.ContentMarkdown,
71+
renderTerminal(response.ContentMarkdown),
6572
)
6673
if len(response.Replies) > 0 {
6774
writeToTextView(textView,
@@ -74,7 +81,7 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
7481
fmt.Sprintf("\n\t%d", indreply+1),
7582
fmt.Sprintf("\t---"),
7683
fmt.Sprintf("\tAuthor: %s", reply.Author.Name),
77-
fmt.Sprintf("\t%s", reply.ContentMarkdown),
84+
fmt.Sprintf("\t%s", renderTerminal(reply.ContentMarkdown)),
7885
)
7986

8087
}
@@ -106,3 +113,12 @@ func writeToTextView(t *tview.TextView, contents ...string) {
106113
t.Write([]byte("\n"))
107114
}
108115
}
116+
117+
func renderTerminal(content string) string {
118+
r := console.Console{}
119+
out := string(blackfriday.Run([]byte(content),
120+
blackfriday.WithRenderer(r),
121+
blackfriday.WithExtensions(blackfriday.CommonExtensions)))
122+
return out
123+
124+
}

0 commit comments

Comments
 (0)