return path
}
+// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer.
func HasAsciidoc() bool {
return getAsciidocExecPath() != ""
}
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)
{"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))
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 {