From 831ea531a1b8b9efbb94144a967bf59d9952a385 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Fri, 18 Jun 2021 14:49:52 +0800 Subject: [PATCH] Update code that recognizes missing pymentize to modern golang; add solution message --- tags/highlight.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tags/highlight.go b/tags/highlight.go index 8bc4253..6a3bc70 100644 --- a/tags/highlight.go +++ b/tags/highlight.go @@ -4,8 +4,10 @@ import ( "bytes" "fmt" "html" + "io/fs" "os" "os/exec" + "path/filepath" "regexp" "strings" @@ -48,12 +50,12 @@ func highlightTag(rc render.Context) (string, error) { } return buf.String(), nil }) - if e, ok := err.(*exec.Error); ok { - if e.Err == exec.ErrNotFound { + if pathErr, ok := err.(*fs.PathError); ok { + if filepath.Base(pathErr.Path) == pygmentizeCmd { r, err = ``+html.EscapeString(s)+``, nil if !warnedMissingPygmentize { warnedMissingPygmentize = true - _, err = fmt.Fprintf(os.Stdout, "%s\nThe {%% highlight %%} tag will use instead\n", err) + _, err = fmt.Fprintf(os.Stdout, "Error: %s\nRun `pip install Pygments` to install %s.\nThe {%% highlight %%} tag will use instead\n", pathErr, pygmentizeCmd) } } }