aboutsummaryrefslogtreecommitdiff
path: root/chroma.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-05 18:26:51 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-05 18:26:51 +0800
commit4f4f6a25be2625b4bb2cb10e3520f52c4a35c243 (patch)
tree5458da1ee5efa5e46e831c34c1f39ebc67fb71b0 /chroma.go
parentRemove renderReadmeAtTree (diff)
downloadforge-4f4f6a25be2625b4bb2cb10e3520f52c4a35c243.tar.gz
forge-4f4f6a25be2625b4bb2cb10e3520f52c4a35c243.tar.zst
forge-4f4f6a25be2625b4bb2cb10e3520f52c4a35c243.zip
Separate code/README rendering and unsafe to their own packages
Diffstat (limited to 'chroma.go')
-rw-r--r--chroma.go35
1 files changed, 0 insertions, 35 deletions
diff --git a/chroma.go b/chroma.go
deleted file mode 100644
index 0d904b7..0000000
--- a/chroma.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package main
-
-import (
- "bytes"
- "html/template"
-
- chromaHTML "github.com/alecthomas/chroma/v2/formatters/html"
- chromaLexers "github.com/alecthomas/chroma/v2/lexers"
- chromaStyles "github.com/alecthomas/chroma/v2/styles"
-)
-
-func renderHighlightedFile(filename, content string) template.HTML {
- lexer := chromaLexers.Match(filename)
- if lexer == nil {
- lexer = chromaLexers.Fallback
- }
-
- iterator, err := lexer.Tokenise(nil, content)
- if err != nil {
- return template.HTML("<pre>Error tokenizing file: " + err.Error() + "</pre>") //#nosec G203`
- }
-
- var buf bytes.Buffer
- style := chromaStyles.Get("autumn")
- formatter := chromaHTML.New(
- chromaHTML.WithClasses(true),
- chromaHTML.TabWidth(8),
- )
-
- if err := formatter.Format(&buf, style, iterator); err != nil {
- return template.HTML("<pre>Error formatting file: " + err.Error() + "</pre>") //#nosec G203
- }
-
- return template.HTML(buf.Bytes()) //#nosec G203
-}