Add Rst shortcode test
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 4 Jul 2016 08:49:20 +0000 (10:49 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 4 Jul 2016 08:49:20 +0000 (10:49 +0200)
Fixes #2253

helpers/content.go
hugolib/shortcode_test.go

index 94cc3e8537a3fd6aa10777cf1f0be4a071481c2f..709dc8a9758b69d13add8795d91d174c0bb7eecb 100644 (file)
@@ -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,20 +498,35 @@ func getAsciidocContent(content []byte) string {
        return out.String()
 }
 
-// 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)
+// 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 {
-                       jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
-                               "                 Leaving reStructuredText content unrendered.")
-                       return (string(content))
+                       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 := 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")
        cmd.Stdin = bytes.NewReader(cleanContent)
index 79fb0c72e460d37c8e209e0122d11626e90e0bc8..3639bb24ba672da3cba7cbbf6c726727a6c92c36 100644 (file)
@@ -470,6 +470,9 @@ e`,
                {"sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`,
                        filepath.FromSlash("sect/doc7/index.html"),
                        "<div class=\"paragraph\">\n<p><em>Shortcodes:</em> <strong>b: b c: c</strong></p>\n</div>\n"},
+               {"sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`,
+                       filepath.FromSlash("sect/doc8/index.html"),
+                       "<div class=\"document\">\n\n\n<p><strong>Shortcodes:</strong> <em>b: b c: c</em></p>\n</div>"},
        }
 
        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 {