summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-01-31 11:53:21 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-01-31 19:08:19 +0100
commitc52045bbb38cbf64b9cb39352230060aa122cc9f (patch)
tree4fb593b4d9ffc02ba5ece270c86437d5d6ddf809 /hugolib
parent8ed2a1caa9e0892d5bf97ed1b7279befa159f764 (diff)
Fix some inline shortcode issues
Fixes #5645 Fixes #5653
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/shortcode.go18
-rw-r--r--hugolib/shortcode_test.go47
2 files changed, 47 insertions, 18 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 6d87414a7..cd2f268f1 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -338,14 +338,9 @@ func (s *shortcodeHandler) prepareShortcodeForPage(placeholder string, sc *short
if sc.isInline {
key := newScKeyFromLangAndOutputFormat(lang, p.outputFormats[0], placeholder)
- if !s.enableInlineShortcodes {
- m[key] = func() (string, error) {
- return "", nil
- }
- } else {
- m[key] = func() (string, error) {
- return renderShortcode(key, sc, nil, p)
- }
+ m[key] = func() (string, error) {
+ return renderShortcode(key, sc, nil, p)
+
}
return m
@@ -372,6 +367,9 @@ func renderShortcode(
var tmpl tpl.Template
if sc.isInline {
+ if !p.s.enableInlineShortcodes {
+ return "", nil
+ }
templName := path.Join("_inline_shortcode", p.Path(), sc.name)
if sc.isClosing {
templStr := sc.innerString()
@@ -542,6 +540,10 @@ func (s *shortcodeHandler) contentShortcodesForOutputFormat(f output.Format) *or
if !found && key.Suffix != "html" {
key.Suffix = "html"
renderFn, found = s.contentShortcodes.Get(key)
+ if !found {
+ key.OutputFormat = "HTML"
+ renderFn, found = s.contentShortcodes.Get(key)
+ }
}
if !found {
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 9545301ea..16ff0b780 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -1076,40 +1076,67 @@ enableInlineShortcodes = %t
b := newTestSitesBuilder(t)
b.WithConfigFile("toml", conf)
- b.WithContent("page-md-shortcode.md", `---
-title: "Hugo"
----
-FIRST:{{< myshort.inline "first" >}}
+ shortcodeContent := `FIRST:{{< myshort.inline "first" >}}
Page: {{ .Page.Title }}
Seq: {{ seq 3 }}
Param: {{ .Get 0 }}
{{< /myshort.inline >}}:END:
SECOND:{{< myshort.inline "second" />}}:END
+NEW INLINE: {{< n1.inline "5" >}}W1: {{ seq (.Get 0) }}{{< /n1.inline >}}:END:
+INLINE IN INNER: {{< outer >}}{{< n2.inline >}}W2: {{ seq 4 }}{{< /n2.inline >}}{{< /outer >}}:END:
+REUSED INLINE IN INNER: {{< outer >}}{{< n1.inline "3" />}}{{< /outer >}}:END:
+`
-`)
+ b.WithContent("page-md-shortcode.md", `---
+title: "Hugo"
+---
+`+shortcodeContent)
+
+ b.WithContent("_index.md", `---
+title: "Hugo Home"
+---
+
+`+shortcodeContent)
b.WithTemplatesAdded("layouts/_default/single.html", `
CONTENT:{{ .Content }}
`)
+ b.WithTemplatesAdded("layouts/index.html", `
+CONTENT:{{ .Content }}
+`)
+
+ b.WithTemplatesAdded("layouts/shortcodes/outer.html", `Inner: {{ .Inner }}`)
+
b.CreateSites().Build(BuildCfg{})
+ shouldContain := []string{
+ "Seq: [1 2 3]",
+ "Param: first",
+ "Param: second",
+ "NEW INLINE: W1: [1 2 3 4 5]",
+ "INLINE IN INNER: Inner: W2: [1 2 3 4]",
+ "REUSED INLINE IN INNER: Inner: W1: [1 2 3]",
+ }
+
if enableInlineShortcodes {
b.AssertFileContent("public/page-md-shortcode/index.html",
- "Page: Hugo",
- "Seq: [1 2 3]",
- "Param: first",
- "Param: second",
+ shouldContain...,
+ )
+ b.AssertFileContent("public/index.html",
+ shouldContain...,
)
} else {
b.AssertFileContent("public/page-md-shortcode/index.html",
"FIRST::END",
"SECOND::END",
+ "NEW INLINE: :END",
+ "INLINE IN INNER: Inner: :END:",
+ "REUSED INLINE IN INNER: Inner: :END:",
)
}
-
})
}