Skip to content

Commit

Permalink
fix(parse-frontmatter): issue with CR in content extract
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Jan 21, 2025
1 parent 4010272 commit d68cbea
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ export function stringifyCodeBlockProps(data: any, content = '') {
export function parseFrontMatter(content: string) {
let data: any = {}
if (content.startsWith(FRONTMATTER_DELIMITER_DEFAULT)) {
let idx = content.indexOf(LF + FRONTMATTER_DELIMITER_DEFAULT)
const idx = content.indexOf(LF + FRONTMATTER_DELIMITER_DEFAULT)
if (idx !== -1) {
if (content[idx - 1] === CR) {
idx -= 1
}
const frontmatter = content.slice(4, idx)
const hasCarriageReturn = content[idx - 1] === CR
const frontmatter = content.slice(4, idx - (hasCarriageReturn ? 1 : 0))
if (frontmatter) {
data = parse(frontmatter)
content = content.slice(idx + 4)
content = content.slice(idx + 4 + (hasCarriageReturn ? 1 : 0))
}
}
}
Expand Down

0 comments on commit d68cbea

Please sign in to comment.