Skip to content

Commit b60aa1a

Browse files
goodness-from-meanthonyfok
authored andcommitted
helpers: Add --trace to asciidoctor args
This will help to understand and fix errors by seeing stacktrace of an error. See #3714
1 parent ff433f9 commit b60aa1a

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

‎helpers/content.go‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,36 +544,58 @@ func truncateWordsToWholeSentenceOld(content string, max int) (string, bool) {
544544
}
545545

546546
func getAsciidocExecPath() string {
547-
path, err := exec.LookPath("asciidoctor")
547+
path, err := exec.LookPath("asciidoc")
548548
if err != nil {
549-
path, err = exec.LookPath("asciidoc")
550-
if err != nil {
551-
return ""
552-
}
549+
return ""
553550
}
554551
return path
555552
}
556553

557-
// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer.
554+
// HasAsciidoc returns whether Asciidoc is installed on this computer.
558555
func HasAsciidoc() bool {
559556
return getAsciidocExecPath() != ""
560557
}
561558

559+
func getAsciidoctorExecPath() string {
560+
path, err := exec.LookPath("asciidoctor")
561+
if err != nil {
562+
return ""
563+
}
564+
return path
565+
}
566+
567+
// HasAsciidoctor returns whether Asciidoctor is installed on this computer.
568+
func HasAsciidoctor() bool {
569+
return getAsciidoctorExecPath() != ""
570+
}
571+
562572
// getAsciidocContent calls asciidoctor or asciidoc as an external helper
563573
// to convert AsciiDoc content to HTML.
564574
func getAsciidocContent(ctx *RenderingContext) []byte {
565575
content := ctx.Content
566576
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
567577

568-
path := getAsciidocExecPath()
578+
var isAsciidoctor bool
579+
path := getAsciidoctorExecPath()
569580
if path == "" {
570-
jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
571-
" Leaving AsciiDoc content unrendered.")
572-
return content
581+
path = getAsciidocExecPath()
582+
if path == "" {
583+
jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
584+
" Leaving AsciiDoc content unrendered.")
585+
return content
586+
}
587+
} else {
588+
isAsciidoctor = true
573589
}
574590

575591
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
576-
cmd := exec.Command(path, "--no-header-footer", "--safe", "-")
592+
args := []string{"--no-header-footer", "--safe"}
593+
if isAsciidoctor {
594+
// asciidoctor-specific arg to show stack traces on errors
595+
args = append(args, "--trace")
596+
}
597+
args = append(args, "-")
598+
cmd := exec.Command(path, args...)
577599
cmd.Stdin = bytes.NewReader(cleanContent)
578600
var out, cmderr bytes.Buffer
579601
cmd.Stdout = &out

‎hugolib/page_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ func testAllMarkdownEnginesForPages(t *testing.T,
561561
}{
562562
{"md", func() bool { return true }},
563563
{"mmark", func() bool { return true }},
564-
{"ad", func() bool { return helpers.HasAsciidoc() }},
564+
{"ad", func() bool { return helpers.HasAsciidoctor() || helpers.HasAsciidoc() }},
565565
// TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }},
566566
{"rst", func() bool { return helpers.HasRst() }},
567567
}

‎hugolib/shortcode_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ tags:
555555
th := testHelper{s.Cfg, s.Fs, t}
556556

557557
for _, test := range tests {
558-
if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() {
558+
if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoctor() && !helpers.HasAsciidoc() {
559559
fmt.Println("Skip Asciidoc test case as no Asciidoc present.")
560560
continue
561561
} else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() {

0 commit comments

Comments
 (0)