Skip to content

Commit d250eef

Browse files
authored
fix: require triple delimiter for frontmatter parsing (#1102)
Only treat frontmatter as present when the document starts with `---` or `+++`. Adds a regression test for list-item text followed by a fenced code block so leading single `-` no longer yields zero cells. Signed-off-by: Sebastian (Tiedtke) Huckleberry <sebastiantiedtke@gmail.com>
1 parent e3c4bfb commit d250eef

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

document/editor/editor_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,39 @@ A paragraph
842842
string(result),
843843
)
844844
})
845+
846+
t.Run("FencedCodeBlockAfterListItemParagraph", func(t *testing.T) {
847+
bulletMD := []byte(`- After approving the network permission prompt, retry the request with certificate verification disabled so the site can be contacted despite the untrusted chain.
848+
` + "```" + `bash
849+
curl -k -i https://hello.visr.dev
850+
` + "```" + `
851+
`)
852+
853+
notebook, err := Deserialize(bulletMD, Options{IdentityResolver: identityResolverNone})
854+
require.NoError(t, err)
855+
856+
require.GreaterOrEqual(t, len(notebook.Cells), 2)
857+
858+
foundCodeCell := false
859+
for _, cell := range notebook.Cells {
860+
if cell.Kind == CodeKind && cell.LanguageID == "bash" {
861+
foundCodeCell = true
862+
require.Contains(t, cell.Value, "curl -k -i https://hello.visr.dev")
863+
}
864+
}
865+
require.True(t, foundCodeCell, "expected a bash code cell from fenced block")
866+
867+
result, err := Serialize(notebook, nil, Options{})
868+
require.NoError(t, err)
869+
870+
expected := `- After approving the network permission prompt, retry the request with certificate verification disabled so the site can be contacted despite the untrusted chain.
871+
872+
` + "```" + `bash
873+
curl -k -i https://hello.visr.dev
874+
` + "```" + `
875+
`
876+
assert.Equal(t, expected, string(result))
877+
})
845878
}
846879

847880
func TestEditor_AttributeFormat(t *testing.T) {

document/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ loop:
167167
}
168168

169169
switch {
170-
case r0 == '+':
170+
case r0 == '+' && ahead[0] == '+' && ahead[1] == '+':
171171
return parseRawFrontmatter(l, byte(r0))
172172
case r0 == '-' && ahead[0] == '-' && ahead[1] == '8' && ahead[2] == '<':
173173
// skip scissor syntax
174174
l.backup(r0)
175175
break loop
176-
case r0 == '-':
176+
case r0 == '-' && ahead[0] == '-' && ahead[1] == '-':
177177
return parseRawFrontmatter(l, byte(r0))
178178
case r0 == '{' && ahead[0] == '{':
179179
// skip markdown templates

0 commit comments

Comments
 (0)