From 590777dea0839a655dc468900b306d880e9fa16a Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 31 Jul 2024 22:18:17 -0500 Subject: [PATCH] feat: custom lexer registry Signed-off-by: jolheiser --- internal/html/markup/chroma.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/html/markup/chroma.go b/internal/html/markup/chroma.go index c1d83f3..57efa72 100644 --- a/internal/html/markup/chroma.go +++ b/internal/html/markup/chroma.go @@ -2,6 +2,7 @@ package markup import ( "io" + "path/filepath" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/formatters/html" @@ -26,10 +27,17 @@ var ( type code struct{} +var customReg = map[string]string{ + ".hujson": "json", +} + func setup(source []byte, fileName string) (chroma.Iterator, *chroma.Style, error) { lexer := lexers.Match(fileName) if lexer == nil { lexer = lexers.Fallback + if name, ok := customReg[filepath.Ext(fileName)]; ok { + lexer = lexers.Get(name) + } } lexer = chroma.Coalesce(lexer)