diff options
author | spf13 <steve.francia@gmail.com> | 2014-01-10 12:50:31 -0500 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-01-10 21:28:48 -0500 |
commit | 01da9a40e69b22e18886d56dd5b90ca9ef488911 (patch) | |
tree | 1a8236f206dde370f0e9c590dd3e07794f05cd03 /helpers/pygments.go | |
parent | 3fd6c1a24e4f159ee300f0b6dbc177615455e5d6 (diff) |
Report error, but don’t fatally stop if pygments has error. Return original string. (+1 squashed commit)
Squashed commits:
[849a7af] if highlighting doesn’t work, just return original string
Diffstat (limited to 'helpers/pygments.go')
-rw-r--r-- | helpers/pygments.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/helpers/pygments.go b/helpers/pygments.go index 6b912fc1a..7d22faf7d 100644 --- a/helpers/pygments.go +++ b/helpers/pygments.go @@ -14,32 +14,32 @@ package helpers import ( - "bytes" - "log" - "os/exec" - "strings" + "bytes" + "log" + "os/exec" + "strings" ) func Highlight(code string, lexer string) string { - var pygmentsBin = "pygmentize" + var pygmentsBin = "pygmentize" - if _, err := exec.LookPath(pygmentsBin); err != nil { - log.Print("Highlighting requries Pygments to be installed and in the path") - return code - } + if _, err := exec.LookPath(pygmentsBin); err != nil { + log.Print("Highlighting requries Pygments to be installed and in the path") + return code + } - var out bytes.Buffer - var stderr bytes.Buffer + var out bytes.Buffer + var stderr bytes.Buffer - cmd := exec.Command(pygmentsBin, "-l"+lexer, "-fhtml", "-O style=monokai,noclasses=true,encoding=utf-8") - cmd.Stdin = strings.NewReader(code) - cmd.Stdout = &out - cmd.Stderr = &stderr + cmd := exec.Command(pygmentsBin, "-l"+lexer, "-fhtml", "-O style=monokai,noclasses=true,encoding=utf-8") + cmd.Stdin = strings.NewReader(code) + cmd.Stdout = &out + cmd.Stderr = &stderr - if err := cmd.Run(); err != nil { - log.Print(stderr.String()) - log.Fatal(err) - } + if err := cmd.Run(); err != nil { + log.Print(stderr.String()) + return code + } - return out.String() + return out.String() } |