mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
markup/highlight: Fix chroma highlight
* Use chroma.Coalesce * Escape code strings if lexer is nil Fixes #6877 Fixes #6856
This commit is contained in:
@@ -15,6 +15,7 @@ package highlight
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
gohtml "html"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -63,7 +64,7 @@ func highlight(code, lang string, cfg Config) (string, error) {
|
||||
if lexer == nil {
|
||||
wrapper := getPreWrapper(lang)
|
||||
fmt.Fprint(w, wrapper.Start(true, ""))
|
||||
fmt.Fprint(w, code)
|
||||
fmt.Fprint(w, gohtml.EscapeString(code))
|
||||
fmt.Fprint(w, wrapper.End(true))
|
||||
return w.String(), nil
|
||||
}
|
||||
@@ -72,6 +73,7 @@ func highlight(code, lang string, cfg Config) (string, error) {
|
||||
if style == nil {
|
||||
style = styles.Fallback
|
||||
}
|
||||
lexer = chroma.Coalesce(lexer)
|
||||
|
||||
iterator, err := lexer.Tokenise(nil, code)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user