From 31a07ae9950259be9afc3db8d10f2b2cbbdbb90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 1 Jun 2024 10:27:10 +0200 Subject: [PATCH] content adapter: Handle separator in content.value Closes #12556 --- .../pagesfromgotmpl_integration_test.go | 26 +++++++++++++++++++ parser/pageparser/pagelexer.go | 7 ++--- parser/pageparser/pagelexer_intro.go | 2 -- parser/pageparser/pageparser_test.go | 11 ++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index cbb2da75c86..f351cbb9871 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -643,3 +643,29 @@ Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}| "Footer: Footer|p2||", ) } + +func TestPagesFromGoTmplMore(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +[markup.goldmark.renderer] +unsafe = true +-- content/s1/_content.gotmpl -- +{{ $page := dict + "content" (dict "mediaType" "text/markdown" "value" "aaa bbb") + "title" "p1" + "path" "p1" + }} + {{ .AddPage $page }} +-- layouts/_default/single.html -- +summary: {{ .Summary }}|content: {{ .Content}} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/s1/p1/index.html", + "

aaa

|content:

aaa

\n

bbb

", + ) +} diff --git a/parser/pageparser/pagelexer.go b/parser/pageparser/pagelexer.go index e3b0f1e5468..960f4bfa995 100644 --- a/parser/pageparser/pagelexer.go +++ b/parser/pageparser/pagelexer.go @@ -70,9 +70,10 @@ type Config struct { // can be set if position of first shortcode is known func newPageLexer(input []byte, stateStart stateFunc, cfg Config) *pageLexer { lexer := &pageLexer{ - input: input, - stateStart: stateStart, - cfg: cfg, + input: input, + stateStart: stateStart, + summaryDivider: summaryDivider, + cfg: cfg, lexerShortcodeState: lexerShortcodeState{ currLeftDelimItem: tLeftDelimScNoMarkup, currRightDelimItem: tRightDelimScNoMarkup, diff --git a/parser/pageparser/pagelexer_intro.go b/parser/pageparser/pagelexer_intro.go index 0ff0958fee5..925c61c9e58 100644 --- a/parser/pageparser/pagelexer_intro.go +++ b/parser/pageparser/pagelexer_intro.go @@ -14,8 +14,6 @@ package pageparser func lexIntroSection(l *pageLexer) stateFunc { - l.summaryDivider = summaryDivider - LOOP: for { r := l.next() diff --git a/parser/pageparser/pageparser_test.go b/parser/pageparser/pageparser_test.go index a50ab46e9d7..c6bedbd6fd3 100644 --- a/parser/pageparser/pageparser_test.go +++ b/parser/pageparser/pageparser_test.go @@ -101,3 +101,14 @@ func BenchmarkHasShortcode(b *testing.B) { } }) } + +func TestSummaryDividerStartingFromMain(t *testing.T) { + c := qt.New(t) + + input := `aaa bbb` + items, err := collectStringMain(input) + c.Assert(err, qt.IsNil) + + c.Assert(items, qt.HasLen, 4) + c.Assert(items[1].Type, qt.Equals, TypeLeadSummaryDivider) +}