Add Asciidoc shortcode test
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 3 Jul 2016 22:33:08 +0000 (00:33 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 3 Jul 2016 22:33:08 +0000 (00:33 +0200)
Fixes #2249

helpers/content.go
hugolib/shortcode_test.go

index 7a6f361c87b8868a28d7309c0b95a240ebe7a9c1..94cc3e8537a3fd6aa10777cf1f0be4a071481c2f 100644 (file)
@@ -458,20 +458,32 @@ func TruncateWordsToWholeSentence(words []string, max int) (string, bool) {
        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, "...")
        cmd := exec.Command(path, "--no-header-footer", "--safe", "-")
index a055d0882334b1649d7538f61b564ab7e214809f..79fb0c72e460d37c8e209e0122d11626e90e0bc8 100644 (file)
@@ -466,6 +466,10 @@ e`,
                {"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 @@ e`,
        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 {