This commit is contained in:
Mark McGranaghan 2012-10-01 17:55:49 -07:00
parent 54e1b4b33c
commit 2281477ac8

View File

@ -7,6 +7,7 @@ import (
"os/exec"
"regexp"
"strings"
"github.com/russross/blackfriday"
)
func check(err error) {
@ -15,14 +16,6 @@ func check(err error) {
}
}
func whichRenderers() (string, string) {
markdownPath, err := exec.LookPath("markdown")
check(err)
pygmentizePath, err := exec.LookPath("pygmentize")
check(err)
return markdownPath, pygmentizePath
}
func render(bin string, arg []string, src string) string {
cmd := exec.Command(bin, arg...)
in, _ := cmd.StdinPipe()
@ -78,8 +71,6 @@ func main() {
os.Exit(1)
}
markdownPath, pygmentizePath := whichRenderers()
fmt.Print(`<!DOCTYPE html>
<html>
<head>
@ -154,10 +145,10 @@ func main() {
for _, seg := range segs {
if seg.docs != "" {
seg.docsRendered = render(markdownPath, []string{}, seg.docs)
seg.docsRendered = string(blackfriday.MarkdownCommon([]byte(seg.docs)))
}
if seg.code != "" {
seg.codeRendered = render(pygmentizePath, []string{"-l", lexer, "-f", "html"}, seg.code)
seg.codeRendered = render("/usr/local/bin/pygmentize", []string{"-l", lexer, "-f", "html"}, seg.code)
}
}