mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Return error from HandleShortcodes
To be able to test for it.
This commit is contained in:
parent
be29c0bfbd
commit
bee1358e48
2 changed files with 10 additions and 6 deletions
|
@ -122,22 +122,22 @@ func (sc shortcode) String() string {
|
||||||
return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner)
|
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
|
// 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)
|
tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t)
|
||||||
|
|
||||||
if len(tmpShortcodes) > 0 {
|
if len(tmpShortcodes) > 0 {
|
||||||
tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, true, tmpShortcodes)
|
tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, true, tmpShortcodes)
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
return string(tmpContentWithTokensReplaced)
|
return string(tmpContentWithTokensReplaced), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(tmpContent)
|
return string(tmpContent), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var isInnerShortcodeCache = struct {
|
var isInnerShortcodeCache = struct {
|
||||||
|
|
|
@ -20,7 +20,11 @@ func pageFromString(in, filename string) (*Page, error) {
|
||||||
func CheckShortCodeMatch(t *testing.T, input, expected string, template tpl.Template) {
|
func CheckShortCodeMatch(t *testing.T, input, expected string, template tpl.Template) {
|
||||||
|
|
||||||
p, _ := pageFromString(SIMPLE_PAGE, "simple.md")
|
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 {
|
if output != expected {
|
||||||
t.Fatalf("Shortcode render didn't match. Expected: %q, Got: %q", expected, output)
|
t.Fatalf("Shortcode render didn't match. Expected: %q, Got: %q", expected, output)
|
||||||
|
|
Loading…
Reference in a new issue