shithub: hugo

Download patch

ref: 5388211c1158b81725af04152c6e73eddc1435a0
parent: 6c0f705217b65c7e91fe22c5b8ca0c3f8b1bf33a
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Jul 3 20:33:08 EDT 2016

Add Asciidoc shortcode test

Fixes #2249

--- a/helpers/content.go
+++ b/helpers/content.go
@@ -458,19 +458,31 @@
 	return strings.Join(words[:max], " "), true
 }
 
-// getAsciidocContent calls asciidoctor or asciidoc as an external helper
-// to convert AsciiDoc content to HTML.
-func getAsciidocContent(content []byte) string {
-	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
-
+func getAsciidocExecPath() string {
 	path, err := exec.LookPath("asciidoctor")
 	if err != nil {
 		path, err = exec.LookPath("asciidoc")
 		if err != nil {
-			jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
-				"                 Leaving AsciiDoc content unrendered.")
-			return (string(content))
+			return ""
 		}
+	}
+	return path
+}
+
+func HasAsciidoc() bool {
+	return getAsciidocExecPath() != ""
+}
+
+// getAsciidocContent calls asciidoctor or asciidoc as an external helper
+// to convert AsciiDoc content to HTML.
+func getAsciidocContent(content []byte) string {
+	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
+
+	path := getAsciidocExecPath()
+	if path == "" {
+		jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
+			"                 Leaving AsciiDoc content unrendered.")
+		return (string(content))
 	}
 
 	jww.INFO.Println("Rendering with", path, "...")
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -466,6 +466,10 @@
 		{"sect/doc6.md", "\n```bash\n{{< b >}}\n{{% c %}}\n```\n",
 			filepath.FromSlash("sect/doc6/index.html"),
 			"<pre><code class=\"language-bash\">b\nc\n</code></pre>\n"},
+		// #2249
+		{"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"},
 	}
 
 	sources := make([]source.ByteSource, len(tests))
@@ -494,6 +498,10 @@
 	createAndRenderPages(t, s)
 
 	for _, test := range tests {
+		if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() {
+			fmt.Println("Skip Asciidoc test case as no Asciidoc present.")
+			continue
+		}
 		file, err := hugofs.Destination().Open(test.outFile)
 
 		if err != nil {