summaryrefslogtreecommitdiffstats
path: root/helpers/pygments.go
diff options
context:
space:
mode:
authorAndrew Brampton <github@bramp.net>2015-07-03 14:51:43 -0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-07-08 08:12:06 +0200
commitfdab118010f3b5ad027038bb2b2040d30478852e (patch)
treef78efb08df4e0c5011784dc3d86675f6a7d3c77b /helpers/pygments.go
parent450dc7a41186bc32812c89a69cf3c5bf89d97435 (diff)
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.
Diffstat (limited to 'helpers/pygments.go')
-rw-r--r--helpers/pygments.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/helpers/pygments.go b/helpers/pygments.go
index 3f0f90b7a..ecbdf99d0 100644
--- a/helpers/pygments.go
+++ b/helpers/pygments.go
@@ -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