templates: use the earliest front matter closing fence (#8259)
This commit is contained in:
parent
0e392c89ba
commit
8ba327ef3f
2 changed files with 13 additions and 3 deletions
|
|
@ -49,15 +49,14 @@ func extractFrontMatter(input string) (map[string]any, string, error) {
|
|||
return nil, input, nil
|
||||
}
|
||||
|
||||
// find end of front matter
|
||||
// find end of front matter: the closing fence that comes first
|
||||
var fmEndFence string
|
||||
fmEndFenceStart := -1
|
||||
for _, fence := range closingFence {
|
||||
index := strings.Index(input[firstLineEnd:], "\n"+fence)
|
||||
if index >= 0 {
|
||||
if index >= 0 && (fmEndFenceStart < 0 || index < fmEndFenceStart) {
|
||||
fmEndFenceStart = index
|
||||
fmEndFence = fence
|
||||
break
|
||||
}
|
||||
}
|
||||
if fmEndFenceStart < 0 {
|
||||
|
|
|
|||
|
|
@ -605,6 +605,17 @@ yeah`,
|
|||
expect: `Welcome`,
|
||||
body: "\n### Test\n...\nyeah",
|
||||
},
|
||||
{
|
||||
// yaml closed with dots, with a '---' rule later in the body
|
||||
input: `---
|
||||
title: Welcome
|
||||
...
|
||||
### Test
|
||||
---
|
||||
yeah`,
|
||||
expect: `Welcome`,
|
||||
body: "\n### Test\n---\nyeah",
|
||||
},
|
||||
{
|
||||
// toml
|
||||
input: `+++
|
||||
|
|
|
|||
Loading…
Reference in a new issue