Monorepo for Tangled tangled.org

appview: render markdown in issues

anirudh.fi 74ac77e6 691360d6

verified
Changed files
+35 -2
appview
pages
templates
repo
issues
+3
appview/pages/funcmap.go
··· 103 103 } 104 104 return v.Slice(start, end).Interface() 105 105 }, 106 + "markdown": func(text string) template.HTML { 107 + return template.HTML(renderMarkdown(text)) 108 + }, 106 109 } 107 110 }
+28
appview/pages/markdown.go
··· 1 + package pages 2 + 3 + import ( 4 + "bytes" 5 + 6 + "github.com/yuin/goldmark" 7 + "github.com/yuin/goldmark/extension" 8 + "github.com/yuin/goldmark/parser" 9 + "github.com/yuin/goldmark/renderer/html" 10 + ) 11 + 12 + func renderMarkdown(source string) string { 13 + md := goldmark.New( 14 + goldmark.WithExtensions(extension.GFM), 15 + goldmark.WithParserOptions( 16 + parser.WithAutoHeadingID(), 17 + ), 18 + goldmark.WithRendererOptions( 19 + html.WithHardWraps(), 20 + html.WithXHTML(), 21 + ), 22 + ) 23 + var buf bytes.Buffer 24 + if err := md.Convert([]byte(source), &buf); err != nil { 25 + return source 26 + } 27 + return buf.String() 28 + }
+2 -2
appview/pages/templates/repo/issues/issue.html
··· 42 42 43 43 {{ if .Issue.Body }} 44 44 <article id="body" class="mt-8"> 45 - {{ .Issue.Body | escapeHtml }} 45 + {{ .Issue.Body | markdown }} 46 46 </article> 47 47 {{ end }} 48 48 </section> ··· 83 83 </a> 84 84 </div> 85 85 <div class=""> 86 - {{ nl2br .Body }} 86 + {{ .Body | markdown }} 87 87 </div> 88 88 </div> 89 89 {{ end }}
+1
go.mod
··· 24 24 github.com/russross/blackfriday/v2 v2.1.0 25 25 github.com/sethvargo/go-envconfig v1.1.0 26 26 github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e 27 + github.com/yuin/goldmark v1.4.13 27 28 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 28 29 ) 29 30
+1
go.sum
··· 263 263 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 264 264 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 265 265 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 266 + github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= 266 267 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 267 268 gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b h1:CzigHMRySiX3drau9C6Q5CAbNIApmLdat5jPMqChvDA= 268 269 gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b/go.mod h1:/y/V339mxv2sZmYYR64O07VuCpdNZqCTwO8ZcouTMI8=