diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-07-04 00:33:08 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-07-04 00:33:08 +0200 |
commit | 5388211c1158b81725af04152c6e73eddc1435a0 (patch) | |
tree | 93d1ffdb8fd47b617637ae7528d57d47727dc228 /helpers | |
parent | 6c0f705217b65c7e91fe22c5b8ca0c3f8b1bf33a (diff) |
Add Asciidoc shortcode test
Fixes #2249
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/helpers/content.go b/helpers/content.go index 7a6f361c8..94cc3e853 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -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", "-") |