Skip to content

Commit

Permalink
Merge pull request #35 from autarch/fix-fenced-block-without-info
Browse files Browse the repository at this point in the history
Handle fenced code block without a name
  • Loading branch information
chrishrb authored Jan 11, 2025
2 parents d344b34 + 5a7d1da commit 96ce1d8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"regexp"
"strings"

"github.com/alecthomas/chroma/v2"
chroma_html "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
Expand Down Expand Up @@ -63,7 +64,15 @@ func renderHookCodeBlock(w io.Writer, node ast.Node, theme string) (ast.WalkStat
return ast.GoToNext, true
}

lexer := lexers.Get(string(block.Info))
var lexer chroma.Lexer
if block.Info == nil {
lexer = lexers.Analyse(string(block.Literal))
if lexer == nil {
lexer = lexers.Get("plaintext")
}
} else {
lexer = lexers.Get(string(block.Info))
}
iterator, _ := lexer.Tokenise(nil, string(block.Literal))
formatter := chroma_html.New(chroma_html.WithClasses(true))
err := formatter.Format(w, styles.Fallback, iterator)
Expand Down

0 comments on commit 96ce1d8

Please sign in to comment.