Skip to content

Commit d68cbea

Browse files
committed
fix(parse-frontmatter): issue with CR in content extract
1 parent 4010272 commit d68cbea

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/frontmatter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ export function stringifyCodeBlockProps(data: any, content = '') {
4545
export function parseFrontMatter(content: string) {
4646
let data: any = {}
4747
if (content.startsWith(FRONTMATTER_DELIMITER_DEFAULT)) {
48-
let idx = content.indexOf(LF + FRONTMATTER_DELIMITER_DEFAULT)
48+
const idx = content.indexOf(LF + FRONTMATTER_DELIMITER_DEFAULT)
4949
if (idx !== -1) {
50-
if (content[idx - 1] === CR) {
51-
idx -= 1
52-
}
53-
const frontmatter = content.slice(4, idx)
50+
const hasCarriageReturn = content[idx - 1] === CR
51+
const frontmatter = content.slice(4, idx - (hasCarriageReturn ? 1 : 0))
5452
if (frontmatter) {
5553
data = parse(frontmatter)
56-
content = content.slice(idx + 4)
54+
content = content.slice(idx + 4 + (hasCarriageReturn ? 1 : 0))
5755
}
5856
}
5957
}

0 commit comments

Comments
 (0)