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:
Andrew Brampton 2015-07-03 14:51:43 -07:00 committed by Bjørn Erik Pedersen
parent 450dc7a411
commit fdab118010

View file

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