diff --git a/helpers/content.go b/helpers/content.go index 94cc3e853..709dc8a97 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -469,6 +469,7 @@ func getAsciidocExecPath() string { return path } +// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer. func HasAsciidoc() bool { return getAsciidocExecPath() != "" } @@ -497,19 +498,34 @@ func getAsciidocContent(content []byte) string { return out.String() } +// HasRst returns whether rst2html is installed on this computer. +func HasRst() bool { + return getRstExecPath() != "" +} + +func getRstExecPath() string { + path, err := exec.LookPath("rst2html") + if err != nil { + path, err = exec.LookPath("rst2html.py") + if err != nil { + return "" + } + } + return path +} + // getRstContent calls the Python script rst2html as an external helper // to convert reStructuredText content to HTML. func getRstContent(content []byte) string { cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1) - path, err := exec.LookPath("rst2html") - if err != nil { - path, err = exec.LookPath("rst2html.py") - if err != nil { - jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n", - " Leaving reStructuredText content unrendered.") - return (string(content)) - } + path := getRstExecPath() + + if path == "" { + jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n", + " Leaving reStructuredText content unrendered.") + return (string(content)) + } cmd := exec.Command(path, "--leave-comments") diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 79fb0c72e..3639bb24b 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -470,6 +470,9 @@ e`, {"sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`, filepath.FromSlash("sect/doc7/index.html"), "
\n

Shortcodes: b: b c: c

\n
\n"}, + {"sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`, + filepath.FromSlash("sect/doc8/index.html"), + "
\n\n\n

Shortcodes: b: b c: c

\n
"}, } sources := make([]source.ByteSource, len(tests)) @@ -501,7 +504,11 @@ e`, if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() { fmt.Println("Skip Asciidoc test case as no Asciidoc present.") continue + } else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() { + fmt.Println("Skip Rst test case as no rst2html present.") + continue } + file, err := hugofs.Destination().Open(test.outFile) if err != nil {