parseFrontmatter() — astro Function Reference
Architecture documentation for the parseFrontmatter() function in frontmatter.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD ace3779e_c455_f555_b47c_50715d6feef3["parseFrontmatter()"] 527bec49_26ec_0a56_3702_bf73cfac4e0b["frontmatter.ts"] ace3779e_c455_f555_b47c_50715d6feef3 -->|defined in| 527bec49_26ec_0a56_3702_bf73cfac4e0b 1a1e8aea_c0f2_f6da_65b3_920d02af3f9e["extractFrontmatter()"] ace3779e_c455_f555_b47c_50715d6feef3 -->|calls| 1a1e8aea_c0f2_f6da_65b3_920d02af3f9e 14ceab37_b9aa_c45b_2a05_7558b5212412["getFrontmatterParser()"] ace3779e_c455_f555_b47c_50715d6feef3 -->|calls| 14ceab37_b9aa_c45b_2a05_7558b5212412 style ace3779e_c455_f555_b47c_50715d6feef3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/markdown/remark/src/frontmatter.ts lines 46–86
export function parseFrontmatter(
code: string,
options?: ParseFrontmatterOptions,
): ParseFrontmatterResult {
const rawFrontmatter = extractFrontmatter(code);
if (rawFrontmatter == null) {
return { frontmatter: {}, rawFrontmatter: '', content: code };
}
const [delims, parser] = getFrontmatterParser(code);
const parsed = parser(rawFrontmatter);
const frontmatter = (parsed && typeof parsed === 'object' ? parsed : {}) as Record<string, any>;
let content: string;
switch (options?.frontmatter ?? 'remove') {
case 'preserve':
content = code;
break;
case 'remove':
content = code.replace(`${delims}${rawFrontmatter}${delims}`, '');
break;
case 'empty-with-spaces':
content = code.replace(
`${delims}${rawFrontmatter}${delims}`,
` ${rawFrontmatter.replace(/[^\r\n]/g, ' ')} `,
);
break;
case 'empty-with-lines':
content = code.replace(
`${delims}${rawFrontmatter}${delims}`,
rawFrontmatter.replace(/[^\r\n]/g, ''),
);
break;
}
return {
frontmatter,
rawFrontmatter,
content,
};
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does parseFrontmatter() do?
parseFrontmatter() is a function in the astro codebase, defined in packages/markdown/remark/src/frontmatter.ts.
Where is parseFrontmatter() defined?
parseFrontmatter() is defined in packages/markdown/remark/src/frontmatter.ts at line 46.
What does parseFrontmatter() call?
parseFrontmatter() calls 2 function(s): extractFrontmatter, getFrontmatterParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free