Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/pages: add renderers for readme markdown and code blocks

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
1473ec3e 4268abba

+41
+41
appview/pages/funcmap.go
··· 1 1 package pages 2 2 3 3 import ( 4 + "bytes" 4 5 "context" 5 6 "crypto/hmac" 6 7 "crypto/sha256" ··· 18 17 "strings" 19 18 "time" 20 19 20 + "github.com/alecthomas/chroma/v2" 21 + chromahtml "github.com/alecthomas/chroma/v2/formatters/html" 22 + "github.com/alecthomas/chroma/v2/lexers" 23 + "github.com/alecthomas/chroma/v2/styles" 21 24 "github.com/bluesky-social/indigo/atproto/syntax" 22 25 "github.com/dustin/go-humanize" 23 26 "github.com/go-enry/go-enry/v2" ··· 250 245 htmlString := p.rctx.RenderMarkdown(text) 251 246 sanitized := p.rctx.SanitizeDescription(htmlString) 252 247 return template.HTML(sanitized) 248 + }, 249 + "readme": func(text string) template.HTML { 250 + p.rctx.RendererType = markup.RendererTypeRepoMarkdown 251 + htmlString := p.rctx.RenderMarkdown(text) 252 + sanitized := p.rctx.SanitizeDefault(htmlString) 253 + return template.HTML(sanitized) 254 + }, 255 + "code": func(content, path string) string { 256 + var style *chroma.Style = styles.Get("catpuccin-latte") 257 + formatter := chromahtml.New( 258 + chromahtml.InlineCode(false), 259 + chromahtml.WithLineNumbers(true), 260 + chromahtml.WithLinkableLineNumbers(true, "L"), 261 + chromahtml.Standalone(false), 262 + chromahtml.WithClasses(true), 263 + ) 264 + 265 + lexer := lexers.Get(filepath.Base(path)) 266 + if lexer == nil { 267 + lexer = lexers.Fallback 268 + } 269 + 270 + iterator, err := lexer.Tokenise(nil, content) 271 + if err != nil { 272 + p.logger.Error("chroma tokenize", "err", "err") 273 + return "" 274 + } 275 + 276 + var code bytes.Buffer 277 + err = formatter.Format(&code, style, iterator) 278 + if err != nil { 279 + p.logger.Error("chroma format", "err", "err") 280 + return "" 281 + } 282 + 283 + return code.String() 253 284 }, 254 285 "trimUriScheme": func(text string) string { 255 286 text = strings.TrimPrefix(text, "https://")