diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-01-31 11:53:21 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-01-31 19:08:19 +0100 |
commit | c52045bbb38cbf64b9cb39352230060aa122cc9f (patch) | |
tree | 4fb593b4d9ffc02ba5ece270c86437d5d6ddf809 /parser | |
parent | 8ed2a1caa9e0892d5bf97ed1b7279befa159f764 (diff) | |
download | hugo-c52045bbb38cbf64b9cb39352230060aa122cc9f.tar.gz hugo-c52045bbb38cbf64b9cb39352230060aa122cc9f.zip |
Fix some inline shortcode issues
Fixes #5645
Fixes #5653
Diffstat (limited to 'parser')
-rw-r--r-- | parser/pageparser/pagelexer_shortcode.go | 1 | ||||
-rw-r--r-- | parser/pageparser/pageparser_shortcode_test.go | 14 |
2 files changed, 11 insertions, 4 deletions
diff --git a/parser/pageparser/pagelexer_shortcode.go b/parser/pageparser/pagelexer_shortcode.go index fe182459a..d503d1797 100644 --- a/parser/pageparser/pagelexer_shortcode.go +++ b/parser/pageparser/pagelexer_shortcode.go @@ -280,6 +280,7 @@ func lexInsideShortcode(l *pageLexer) stateFunc { return l.errorf("got closing shortcode, but none is open") } l.closingState++ + l.isInline = false l.emit(tScClose) case r == '\\': l.ignore() diff --git a/parser/pageparser/pageparser_shortcode_test.go b/parser/pageparser/pageparser_shortcode_test.go index dc3af5a01..75ee56090 100644 --- a/parser/pageparser/pageparser_shortcode_test.go +++ b/parser/pageparser/pageparser_shortcode_test.go @@ -24,6 +24,7 @@ var ( tstSCClose = nti(tScClose, "/") tstSC1 = nti(tScName, "sc1") tstSC1Inline = nti(tScNameInline, "sc1.inline") + tstSC2Inline = nti(tScNameInline, "sc2.inline") tstSC2 = nti(tScName, "sc2") tstSC3 = nti(tScName, "sc3") tstSCSlash = nti(tScName, "sc/sub") @@ -152,6 +153,9 @@ var shortCodeLexerTests = []lexerTest{ {"basic inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}}, {"basic inline with space", `{{< sc1.inline >}}Hello World{{< / sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}}, {"inline self closing", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD, tstEOF}}, + {"inline self closing, then a new inline", `{{< sc1.inline >}}Hello World{{< /sc1.inline >}}Hello World{{< sc1.inline />}}{{< sc2.inline >}}Hello World{{< /sc2.inline >}}`, []Item{ + tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSC1Inline, tstSCClose, tstRightNoMD, + tstLeftNoMD, tstSC2Inline, tstRightNoMD, tstText, tstLeftNoMD, tstSCClose, tstSC2Inline, tstRightNoMD, tstEOF}}, {"inline with template syntax", `{{< sc1.inline >}}{{ .Get 0 }}{{ .Get 1 }}{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, nti(tText, "{{ .Get 0 }}"), nti(tText, "{{ .Get 1 }}"), tstLeftNoMD, tstSCClose, tstSC1Inline, tstRightNoMD, tstEOF}}, {"inline with nested shortcode (not supported)", `{{< sc1.inline >}}Hello World{{< sc1 >}}{{< /sc1.inline >}}`, []Item{tstLeftNoMD, tstSC1Inline, tstRightNoMD, tstText, nti(tError, "inline shortcodes do not support nesting")}}, {"inline case mismatch", `{{< sc1.Inline >}}Hello World{{< /sc1.Inline >}}`, []Item{tstLeftNoMD, nti(tError, "period in shortcode name only allowed for inline identifiers")}}, @@ -160,10 +164,12 @@ var shortCodeLexerTests = []lexerTest{ func TestShortcodeLexer(t *testing.T) { t.Parallel() for i, test := range shortCodeLexerTests { - items := collect([]byte(test.input), true, lexMainSection) - if !equal(items, test.items) { - t.Errorf("[%d] %s: got\n\t%v\nexpected\n\t%v", i, test.name, items, test.items) - } + t.Run(test.name, func(t *testing.T) { + items := collect([]byte(test.input), true, lexMainSection) + if !equal(items, test.items) { + t.Errorf("[%d] %s: got\n\t%v\nexpected\n\t%v", i, test.name, items, test.items) + } + }) } } |