mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03: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:
parent
54bdcaacae
commit
3c568ad013
2 changed files with 31 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue