diff --git a/packages/markdown/remark/src/frontmatter.ts b/packages/markdown/remark/src/frontmatter.ts index d8ed74474e07..94fbec2b3312 100644 --- a/packages/markdown/remark/src/frontmatter.ts +++ b/packages/markdown/remark/src/frontmatter.ts @@ -10,6 +10,9 @@ export function isFrontmatterValid(frontmatter: Record) { return typeof frontmatter === 'object' && frontmatter !== null; } +// Capture frontmatter wrapped with `---`, including any characters and new lines within it. +// Only capture if it exists near the top of the file (whitespaces between the start of file and +// the start of `---` are allowed) const frontmatterRE = /^\s*---([\s\S]*?\n)---/; export function extractFrontmatter(code: string): string | undefined { return frontmatterRE.exec(code)?.[1];