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: migrate string templates to use funcmap renderers

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

authored by

oppiliappan and committed by
Tangled
ed277aad 272a0aa3

+2 -45
-43
appview/pages/pages.go
··· 1 1 package pages 2 2 3 3 import ( 4 - "bytes" 5 4 "crypto/sha256" 6 5 "embed" 7 6 "encoding/hex" ··· 28 29 "tangled.org/core/patchutil" 29 30 "tangled.org/core/types" 30 31 31 - "github.com/alecthomas/chroma/v2" 32 - chromahtml "github.com/alecthomas/chroma/v2/formatters/html" 33 - "github.com/alecthomas/chroma/v2/lexers" 34 - "github.com/alecthomas/chroma/v2/styles" 35 32 "github.com/bluesky-social/indigo/atproto/identity" 36 33 "github.com/bluesky-social/indigo/atproto/syntax" 37 34 "github.com/go-git/go-git/v5/plumbing" ··· 1382 1387 } 1383 1388 1384 1389 func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error { 1385 - var style *chroma.Style = styles.Get("catpuccin-latte") 1386 - 1387 - if params.ShowRendered { 1388 - switch markup.GetFormat(params.String.Filename) { 1389 - case markup.FormatMarkdown: 1390 - p.rctx.RendererType = markup.RendererTypeRepoMarkdown 1391 - htmlString := p.rctx.RenderMarkdown(params.String.Contents) 1392 - sanitized := p.rctx.SanitizeDefault(htmlString) 1393 - params.RenderedContents = template.HTML(sanitized) 1394 - } 1395 - } 1396 - 1397 - c := params.String.Contents 1398 - formatter := chromahtml.New( 1399 - chromahtml.InlineCode(false), 1400 - chromahtml.WithLineNumbers(true), 1401 - chromahtml.WithLinkableLineNumbers(true, "L"), 1402 - chromahtml.Standalone(false), 1403 - chromahtml.WithClasses(true), 1404 - ) 1405 - 1406 - lexer := lexers.Get(filepath.Base(params.String.Filename)) 1407 - if lexer == nil { 1408 - lexer = lexers.Fallback 1409 - } 1410 - 1411 - iterator, err := lexer.Tokenise(nil, c) 1412 - if err != nil { 1413 - return fmt.Errorf("chroma tokenize: %w", err) 1414 - } 1415 - 1416 - var code bytes.Buffer 1417 - err = formatter.Format(&code, style, iterator) 1418 - if err != nil { 1419 - return fmt.Errorf("chroma format: %w", err) 1420 - } 1421 - 1422 - params.String.Contents = code.String() 1423 1390 return p.execute("strings/string", w, params) 1424 1391 } 1425 1392
+2 -2
appview/pages/templates/strings/string.html
··· 75 75 </div> 76 76 <div class="overflow-x-auto overflow-y-hidden relative"> 77 77 {{ if .ShowRendered }} 78 - <div id="blob-contents" class="prose dark:prose-invert">{{ .RenderedContents }}</div> 78 + <div id="blob-contents" class="prose dark:prose-invert">{{ .String.Contents | readme }}</div> 79 79 {{ else }} 80 - <div id="blob-contents" class="whitespace-pre peer-target:bg-yellow-200 dark:peer-target:bg-yellow-900">{{ .String.Contents | escapeHtml }}</div> 80 + <div id="blob-contents" class="whitespace-pre peer-target:bg-yellow-200 dark:peer-target:bg-yellow-900">{{ code .String.Contents .String.Filename | escapeHtml }}</div> 81 81 {{ end }} 82 82 </div> 83 83 {{ template "fragments/multiline-select" }}