Fix shortcode directly following a shortcode delimiter

Fixes #5402
This commit is contained in:
Bjørn Erik Pedersen 2018-11-05 13:30:16 +01:00
parent 5b1edd281a
commit d16a7a33ff
3 changed files with 20 additions and 3 deletions

View file

@ -1513,7 +1513,13 @@ Content.
b.WithContent("page-md-shortcode-same-line.md", `--- b.WithContent("page-md-shortcode-same-line.md", `---
title: "Hugo" title: "Hugo"
--- ---
This is a {{< sc >}}.<!--more-->Same line. This is a {{< sc >}}<!--more-->Same line.
`)
b.WithContent("page-md-shortcode-same-line-after.md", `---
title: "Hugo"
---
Summary<!--more-->{{< sc >}}
`) `)
b.WithContent("page-org-shortcode.org", `#+TITLE: T1 b.WithContent("page-org-shortcode.org", `#+TITLE: T1
@ -1547,8 +1553,13 @@ CONTENT:{{ .Content }}
) )
b.AssertFileContent("public/page-md-shortcode-same-line/index.html", b.AssertFileContent("public/page-md-shortcode-same-line/index.html",
"SUMMARY:<p>This is a a shortcode.</p>:END", "SUMMARY:<p>This is a a shortcode</p>:END",
"CONTENT:<p>This is a a shortcode.</p>\n\n<p>Same line.</p>\n", "CONTENT:<p>This is a a shortcode</p>\n\n<p>Same line.</p>\n",
)
b.AssertFileContent("public/page-md-shortcode-same-line-after/index.html",
"SUMMARY:<p>Summary</p>:END",
"CONTENT:<p>Summary</p>\n\na shortcode",
) )
b.AssertFileContent("public/page-org-shortcode/index.html", b.AssertFileContent("public/page-org-shortcode/index.html",

View file

@ -247,6 +247,9 @@ func lexMainSection(l *pageLexer) stateFunc {
// This makes it a little easier to reason about later. // This makes it a little easier to reason about later.
l.consumeSpace() l.consumeSpace()
l.emit(TypeLeadSummaryDivider) l.emit(TypeLeadSummaryDivider)
// We have already moved to the next.
continue
} }
} }

View file

@ -68,11 +68,14 @@ var frontMatterTests = []lexerTest{
{"Summary divider ORG", tstORG + "\nSome text.\n# more\nSome text.\n", []Item{tstFrontMatterORG, tstSomeText, nti(TypeLeadSummaryDivider, "# more\n"), nti(tText, "Some text.\n"), tstEOF}}, {"Summary divider ORG", tstORG + "\nSome text.\n# more\nSome text.\n", []Item{tstFrontMatterORG, tstSomeText, nti(TypeLeadSummaryDivider, "# more\n"), nti(tText, "Some text.\n"), tstEOF}},
{"Summary divider", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n<!--more-->\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, tstSummaryDivider, nti(tText, "Some text.\n"), tstEOF}}, {"Summary divider", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n<!--more-->\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, tstSummaryDivider, nti(tText, "Some text.\n"), tstEOF}},
{"Summary divider same line", "+++\nfoo = \"bar\"\n+++\n\nSome text.<!--more-->Some text.\n", []Item{tstFrontMatterTOML, nti(tText, "\nSome text."), nti(TypeLeadSummaryDivider, "<!--more-->"), nti(tText, "Some text.\n"), tstEOF}}, {"Summary divider same line", "+++\nfoo = \"bar\"\n+++\n\nSome text.<!--more-->Some text.\n", []Item{tstFrontMatterTOML, nti(tText, "\nSome text."), nti(TypeLeadSummaryDivider, "<!--more-->"), nti(tText, "Some text.\n"), tstEOF}},
// https://github.com/gohugoio/hugo/issues/5402
{"Summary and shortcode, no space", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n<!--more-->{{< sc1 >}}\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, nti(TypeLeadSummaryDivider, "<!--more-->"), tstLeftNoMD, tstSC1, tstRightNoMD, tstSomeText, tstEOF}},
} }
func TestFrontMatter(t *testing.T) { func TestFrontMatter(t *testing.T) {
t.Parallel() t.Parallel()
for i, test := range frontMatterTests { for i, test := range frontMatterTests {
items := collect([]byte(test.input), false, lexIntroSection) items := collect([]byte(test.input), false, lexIntroSection)
if !equal(items, test.items) { if !equal(items, test.items) {
got := crLfReplacer.Replace(fmt.Sprint(items)) got := crLfReplacer.Replace(fmt.Sprint(items))