mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
If no language is provided to Pygments, then try and guess it
Previously if no language was specified, then illegal args would be passed to pygments, for example `pygments -l -fhtml`, which would result in pygments printing an error.
This commit is contained in:
parent
450dc7a411
commit
fdab118010
1 changed files with 8 additions and 1 deletions
|
@ -94,7 +94,14 @@ func Highlight(code, lang, optsStr string) string {
|
|||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
cmd := exec.Command(pygmentsBin, "-l"+lang, "-fhtml", "-O", options)
|
||||
var langOpt string
|
||||
if lang == "" {
|
||||
langOpt = "-g" // Try guessing the language
|
||||
} else {
|
||||
langOpt = "-l"+lang
|
||||
}
|
||||
|
||||
cmd := exec.Command(pygmentsBin, langOpt, "-fhtml", "-O", options)
|
||||
cmd.Stdin = strings.NewReader(code)
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &stderr
|
||||
|
|
Loading…
Reference in a new issue