forked from tangled.org/core
Monorepo for Tangled — https://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
···
}
return v.Slice(start, end).Interface()
},
+
"markdown": func(text string) template.HTML {
+
return template.HTML(renderMarkdown(text))
+
},
}
}
+28
appview/pages/markdown.go
···
+
package pages
+
+
import (
+
"bytes"
+
+
"github.com/yuin/goldmark"
+
"github.com/yuin/goldmark/extension"
+
"github.com/yuin/goldmark/parser"
+
"github.com/yuin/goldmark/renderer/html"
+
)
+
+
func renderMarkdown(source string) string {
+
md := goldmark.New(
+
goldmark.WithExtensions(extension.GFM),
+
goldmark.WithParserOptions(
+
parser.WithAutoHeadingID(),
+
),
+
goldmark.WithRendererOptions(
+
html.WithHardWraps(),
+
html.WithXHTML(),
+
),
+
)
+
var buf bytes.Buffer
+
if err := md.Convert([]byte(source), &buf); err != nil {
+
return source
+
}
+
return buf.String()
+
}
+2 -2
appview/pages/templates/repo/issues/issue.html
···
{{ if .Issue.Body }}
<article id="body" class="mt-8">
-
{{ .Issue.Body | escapeHtml }}
+
{{ .Issue.Body | markdown }}
</article>
{{ end }}
</section>
···
</a>
</div>
<div class="">
-
{{ nl2br .Body }}
+
{{ .Body | markdown }}
</div>
</div>
{{ end }}
+1
go.mod
···
github.com/russross/blackfriday/v2 v2.1.0
github.com/sethvargo/go-envconfig v1.1.0
github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e
+
github.com/yuin/goldmark v1.4.13
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
)
+1
go.sum
···
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b h1:CzigHMRySiX3drau9C6Q5CAbNIApmLdat5jPMqChvDA=
gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b/go.mod h1:/y/V339mxv2sZmYYR64O07VuCpdNZqCTwO8ZcouTMI8=