templates: use the earliest front matter closing fence (#8259)

This commit is contained in:
Jay Hemnani 2026-10-20 12:37:07 +05:30 committed by GitHub
parent 0e392c89ba
commit 8ba327ef3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -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 {

View file

@ -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: `+++