ref: bee1358e4838b40042963cc41a9d63a395b6541e
parent: be29c0bfbdbb38d0f4e170d235221db09aa20174
author: bep <[email protected]>
date: Wed Apr 29 15:08:34 EDT 2015
Return error from HandleShortcodes To be able to test for it.
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -122,9 +122,9 @@
return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner)
}
-// handleShortcodes does all in one go: extract, render and replace
+// HandleShortcodes does all in one go: extract, render and replace
// only used for testing
-func handleShortcodes(stringToParse string, page *Page, t tpl.Template) string {
+func HandleShortcodes(stringToParse string, page *Page, t tpl.Template) (string, error) {
tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t)
if len(tmpShortcodes) > 0 {
@@ -131,13 +131,13 @@
tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, true, tmpShortcodes)
if err != nil {
- jww.ERROR.Printf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error())
+ return "", fmt.Errorf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error())
} else {
- return string(tmpContentWithTokensReplaced)
+ return string(tmpContentWithTokensReplaced), nil
}
}
- return string(tmpContent)
+ return string(tmpContent), nil
}
var isInnerShortcodeCache = struct {
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -20,7 +20,11 @@
func CheckShortCodeMatch(t *testing.T, input, expected string, template tpl.Template) {
p, _ := pageFromString(SIMPLE_PAGE, "simple.md")
- output := handleShortcodes(input, p, template)
+ output, err := HandleShortcodes(input, p, template)
+
+ if err != nil {
+ t.Fatalf("Shortcode rendered error %s. Expected: %q, Got: %q", err, expected, output)
+ }
if output != expected {
t.Fatalf("Shortcode render didn't match. Expected: %q, Got: %q", expected, output)