MCPcopy Create free account
hub / github.com/openai/plugins / extractFrontmatter

Function extractFrontmatter

plugins/plugin-eval/src/lib/frontmatter.js:210–235  ·  view source on GitHub ↗
(markdown)

Source from the content-addressed store, hash-verified

208}
209
210export function extractFrontmatter(markdown) {
211 const normalized = markdown.replace(/\r\n/g, "\n");
212 const lines = normalized.split("\n");
213 if (lines[0] !== "---") {
214 return {
215 frontmatterText: "",
216 body: normalized,
217 errors: ["No YAML frontmatter found."],
218 };
219 }
220
221 const closingIndex = lines.indexOf("---", 1);
222 if (closingIndex === -1) {
223 return {
224 frontmatterText: "",
225 body: normalized,
226 errors: ["Frontmatter opening delimiter is missing a closing delimiter."],
227 };
228 }
229
230 return {
231 frontmatterText: lines.slice(1, closingIndex).join("\n"),
232 body: lines.slice(closingIndex + 1).join("\n"),
233 errors: [],
234 };
235}
236
237export function parseFrontmatter(markdown) {
238 const extracted = extractFrontmatter(markdown);

Callers 1

parseFrontmatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected