diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-10-30 20:24:34 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-10-31 23:14:37 +0100 |
commit | b2a676f5f09a3eea360887b099b9d5fc25a88492 (patch) | |
tree | a54e01c01a8a507d24e6d8fd85170f03eca54370 /parser | |
parent | 3a786a248d3eff6e732aa94e87d6e88196e5147a (diff) | |
download | hugo-b2a676f5f09a3eea360887b099b9d5fc25a88492.tar.gz hugo-b2a676f5f09a3eea360887b099b9d5fc25a88492.zip |
hugolib: Fix broken manual summary handling
Fixes #5381
Diffstat (limited to 'parser')
-rw-r--r-- | parser/pageparser/pagelexer.go | 12 | ||||
-rw-r--r-- | parser/pageparser/pageparser_intro_test.go | 7 |
2 files changed, 16 insertions, 3 deletions
diff --git a/parser/pageparser/pagelexer.go b/parser/pageparser/pagelexer.go index ddf109b3d..565be2994 100644 --- a/parser/pageparser/pagelexer.go +++ b/parser/pageparser/pagelexer.go @@ -194,6 +194,16 @@ func (l *pageLexer) consumeCRLF() bool { return consumed } +func (l *pageLexer) consumeSpace() { + for { + r := l.next() + if r == eof || !unicode.IsSpace(r) { + l.backup() + return + } + } +} + func lexMainSection(l *pageLexer) stateFunc { // Fast forward as far as possible. var l1, l2 int @@ -234,6 +244,8 @@ func lexMainSection(l *pageLexer) stateFunc { } l.summaryDividerChecked = true l.pos += len(l.summaryDivider) + // This makes it a little easier to reason about later. + l.consumeSpace() l.emit(TypeLeadSummaryDivider) } } diff --git a/parser/pageparser/pageparser_intro_test.go b/parser/pageparser/pageparser_intro_test.go index ba4a2c84b..60c431c10 100644 --- a/parser/pageparser/pageparser_intro_test.go +++ b/parser/pageparser/pageparser_intro_test.go @@ -37,7 +37,7 @@ var ( tstFrontMatterYAMLCRLF = nti(TypeFrontMatterYAML, "foo: \"bar\"\r\n") tstFrontMatterJSON = nti(TypeFrontMatterJSON, tstJSON+"\r\n") tstSomeText = nti(tText, "\nSome text.\n") - tstSummaryDivider = nti(TypeLeadSummaryDivider, "<!--more-->") + tstSummaryDivider = nti(TypeLeadSummaryDivider, "<!--more-->\n") tstHtmlStart = nti(TypeHTMLStart, "<") tstORG = ` @@ -65,8 +65,9 @@ var frontMatterTests = []lexerTest{ {"TOML front matter", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, tstEOF}}, {"JSON front matter", tstJSON + "\r\n\nSome text.\n", []Item{tstFrontMatterJSON, tstSomeText, tstEOF}}, {"ORG front matter", tstORG + "\nSome text.\n", []Item{tstFrontMatterORG, tstSomeText, tstEOF}}, - {"Summary divider ORG", tstORG + "\nSome text.\n# more\nSome text.\n", []Item{tstFrontMatterORG, tstSomeText, nti(TypeLeadSummaryDivider, "# more"), tstSomeText, tstEOF}}, - {"Summary divider", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n<!--more-->\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, tstSummaryDivider, tstSomeText, 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 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}}, } func TestFrontMatter(t *testing.T) { |