shithub: hugo

Download patch

ref: e6d97c4fcadc1d7c843f102cd6500a3060e2a5c3
parent: 5388211c1158b81725af04152c6e73eddc1435a0
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Jul 4 06:49:20 EDT 2016

Add Rst shortcode test

Fixes #2253

--- a/helpers/content.go
+++ b/helpers/content.go
@@ -469,6 +469,7 @@
 	return path
 }
 
+// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer.
 func HasAsciidoc() bool {
 	return getAsciidocExecPath() != ""
 }
@@ -497,19 +498,34 @@
 	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")
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -470,6 +470,9 @@
 		{"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 @@
 		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 {