feat: custom lexer registry

Signed-off-by: jolheiser <git@jolheiser.com>
main
jolheiser 2024-07-31 22:18:17 -05:00
parent df7ace7fae
commit 590777dea0
No known key found for this signature in database
1 changed files with 8 additions and 0 deletions

View File

@ -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)