Use whichPygmentize generated path instead!

This commit is contained in:
Adam Moore 2012-10-12 12:11:14 +09:00
parent 23abb4c310
commit a8f665c1de

View File

@ -70,18 +70,12 @@ func mustReadFile(path string) string {
func cachedPygmentize(lex string, src string) string {
ensureDir(cacheDir)
arg := []string{"-l", lex, "-f", "html"}
bin, err := exec.Command("which", "pygmentize").Output()
if err != nil {
fmt.Println("Please install Pygments and ensure pygmentize is in your path first.")
os.Exit(1)
}
cachePath := cacheDir + "/pygmentize-" + strings.Join(arg, "-") + "-" + sha1Sum(src)
cacheBytes, cacheErr := ioutil.ReadFile(cachePath)
if cacheErr == nil {
return string(cacheBytes)
}
renderBytes := pipe(string(bin), arg, src)
renderBytes := pipe(pygmentizeBin, arg, src)
writeErr := ioutil.WriteFile(cachePath, renderBytes, 0600)
check(writeErr)
return string(renderBytes)