diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 6dfc4ef02..f90093e7a 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -21,6 +21,7 @@ import ( "html/template" "reflect" "regexp" + "sort" "strconv" "strings" ) @@ -90,7 +91,28 @@ type shortcode struct { func (sc shortcode) String() string { // for testing (mostly), so any change here will break tests! - return fmt.Sprintf("%s(%q, %t){%s}", sc.name, sc.params, sc.doMarkup, sc.inner) + var params interface{} + switch v := sc.params.(type) { + case map[string]string: + // sort the keys so test assertions won't fail + var keys []string + for k := range v { + keys = append(keys, k) + } + sort.Strings(keys) + var tmp = make([]string, len(keys)) + + for i, k := range keys { + tmp[i] = k + ":" + v[k] + } + params = tmp + + default: + // use it as is + params = sc.params + } + + return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner) } // all in one go: extract, render and replace diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 91e297805..91b3dad17 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -167,8 +167,8 @@ func TestExtractShortcodes(t *testing.T) { {"one shortcode, markup", "{{% tag %}}", "", testScPlaceholderRegexp, ""}, {"one pos param", "{{% tag param1 %}}", `tag([\"param1\"], true){[]}"]`, testScPlaceholderRegexp, ""}, {"two pos params", "{{< tag param1 param2>}}", `tag([\"param1\" \"param2\"], false){[]}"]`, testScPlaceholderRegexp, ""}, - {"one named param", `{{% tag param1="value" %}}`, `tag(map[\"param1\":\"value\"], true){[]}`, testScPlaceholderRegexp, ""}, - {"two named params", `{{< tag param1="value1" param2="value2" >}}`, `tag(map[\"param1\":\"value1\" \"param2\":\"value2\"], false){[]}"]`, + {"one named param", `{{% tag param1="value" %}}`, `tag([\"param1:value\"], true){[]}`, testScPlaceholderRegexp, ""}, + {"two named params", `{{< tag param1="value1" param2="value2" >}}`, `tag([\"param1:value1\" \"param2:value2\"], false){[]}"]`, testScPlaceholderRegexp, ""}, {"inner", `Some text. {{< inner >}}Inner Content{{< / inner >}}. Some more text.`, `inner([], false){[Inner Content]}`, fmt.Sprintf("Some text. %s. Some more text.", testScPlaceholderRegexp), ""}, @@ -188,10 +188,10 @@ func TestExtractShortcodes(t *testing.T) { `map["
HUGOSHORTCODE-1
:sc1([], false){[]}" "
HUGOSHORTCODE-2
:sc2([], false){[]}"]`, testScPlaceholderRegexp + testScPlaceholderRegexp, ""}, {"mix of shortcodes", `Hello {{< sc1 >}}world{{% sc2 p2="2"%}}. And that's it.`, - `map["
HUGOSHORTCODE-1
:sc1([], false){[]}" "
HUGOSHORTCODE-2
:sc2(map[\"p2\":\"2\"]`, + `map["
HUGOSHORTCODE-1
:sc1([], false){[]}" "
HUGOSHORTCODE-2
:sc2([\"p2:2\"]`, fmt.Sprintf("Hello %sworld%s. And that's it.", testScPlaceholderRegexp, testScPlaceholderRegexp), ""}, {"mix with inner", `Hello {{< sc1 >}}world{{% inner p2="2"%}}Inner{{%/ inner %}}. And that's it.`, - `map["
HUGOSHORTCODE-1
:sc1([], false){[]}" "
HUGOSHORTCODE-2
:inner(map[\"p2\":\"2\"], true){[Inner]}"]`, + `map["
HUGOSHORTCODE-1
:sc1([], false){[]}" "
HUGOSHORTCODE-2
:inner([\"p2:2\"], true){[Inner]}"]`, fmt.Sprintf("Hello %sworld%s. And that's it.", testScPlaceholderRegexp, testScPlaceholderRegexp), ""}, } {