mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-23 09:21:01 +00:00
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
This commit is contained in:
parent
3fd6c1a24e
commit
01da9a40e6
1 changed files with 20 additions and 20 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue