shithub: hugo

Download patch

ref: b60aa1a504f3fbf9c19a6bf2030fdc7a04ab4a5a
parent: ff433f98133662063cbb16e220fd44c678c82823
author: Vasyl Solovei <[email protected]>
date: Fri Jul 21 08:07:56 EDT 2017

helpers: Add --trace to asciidoctor args

This will help to understand and fix errors by
seeing stacktrace of an error.

See #3714

--- a/helpers/content.go
+++ b/helpers/content.go
@@ -544,21 +544,31 @@
 }
 
 func getAsciidocExecPath() string {
-	path, err := exec.LookPath("asciidoctor")
+	path, err := exec.LookPath("asciidoc")
 	if err != nil {
-		path, err = exec.LookPath("asciidoc")
-		if err != nil {
-			return ""
-		}
+		return ""
 	}
 	return path
 }
 
-// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer.
+// HasAsciidoc returns whether Asciidoc is installed on this computer.
 func HasAsciidoc() bool {
 	return getAsciidocExecPath() != ""
 }
 
+func getAsciidoctorExecPath() string {
+	path, err := exec.LookPath("asciidoctor")
+	if err != nil {
+		return ""
+	}
+	return path
+}
+
+// HasAsciidoctor returns whether Asciidoctor is installed on this computer.
+func HasAsciidoctor() bool {
+	return getAsciidoctorExecPath() != ""
+}
+
 // getAsciidocContent calls asciidoctor or asciidoc as an external helper
 // to convert AsciiDoc content to HTML.
 func getAsciidocContent(ctx *RenderingContext) []byte {
@@ -565,15 +575,27 @@
 	content := ctx.Content
 	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
 
-	path := getAsciidocExecPath()
+	var isAsciidoctor bool
+	path := getAsciidoctorExecPath()
 	if path == "" {
-		jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
-			"                 Leaving AsciiDoc content unrendered.")
-		return content
+		path = getAsciidocExecPath()
+		if path == "" {
+			jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
+				"                 Leaving AsciiDoc content unrendered.")
+			return content
+		}
+	} else {
+		isAsciidoctor = true
 	}
 
 	jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
-	cmd := exec.Command(path, "--no-header-footer", "--safe", "-")
+	args := []string{"--no-header-footer", "--safe"}
+	if isAsciidoctor {
+		// asciidoctor-specific arg to show stack traces on errors
+		args = append(args, "--trace")
+	}
+	args = append(args, "-")
+	cmd := exec.Command(path, args...)
 	cmd.Stdin = bytes.NewReader(cleanContent)
 	var out, cmderr bytes.Buffer
 	cmd.Stdout = &out
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -561,7 +561,7 @@
 	}{
 		{"md", func() bool { return true }},
 		{"mmark", func() bool { return true }},
-		{"ad", func() bool { return helpers.HasAsciidoc() }},
+		{"ad", func() bool { return helpers.HasAsciidoctor() || helpers.HasAsciidoc() }},
 		// TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }},
 		{"rst", func() bool { return helpers.HasRst() }},
 	}
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -555,7 +555,7 @@
 	th := testHelper{s.Cfg, s.Fs, t}
 
 	for _, test := range tests {
-		if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() {
+		if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoctor() && !helpers.HasAsciidoc() {
 			fmt.Println("Skip Asciidoc test case as no Asciidoc present.")
 			continue
 		} else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() {