Skip to content

Commit

Permalink
templates: Fix front matter closing fence search
Browse files Browse the repository at this point in the history
This makes it choose first matching closing fence instead of last one,
which could appear in document body.
  • Loading branch information
mholt committed Jul 8, 2020
1 parent efc0cc5 commit a2dae1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/caddyhttp/templates/frontmatter.go
Expand Up @@ -56,6 +56,7 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) {
if index >= 0 {
fmEndFenceStart = index
fmEndFence = fence
break
}
}
if fmEndFenceStart < 0 {
Expand Down
11 changes: 11 additions & 0 deletions modules/caddyhttp/templates/tplcontext_test.go
Expand Up @@ -316,6 +316,17 @@ title: Welcome
expect: `Welcome`,
body: "\n### Test",
},
{
// yaml with non-fence '...' line after closing fence (i.e. first matching closing fence should be used)
input: `---
title: Welcome
---
### Test
...
yeah`,
expect: `Welcome`,
body: "\n### Test\n...\nyeah",
},
{
// toml
input: `+++
Expand Down

0 comments on commit a2dae1d

Please sign in to comment.