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 ("\t Author: %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