// okf-frontmatter.mjs // Minimal flat-frontmatter reader for the shared OKF conformance checker. // Vendored from okr's lib/frontmatter.mjs (the reference implementation) so the // catalog-hosted checker is self-contained — zero npm dependencies, no cross-repo // import. The checker only reads (never writes), so only parseFrontmatter().get is // vendored. Parsing logic is kept byte-identical to okr's so verdicts stay in parity. const FM_RE = /^---\n([\s\S]*?)\n---/; export function parseFrontmatter(content) { const match = String(content).match(FM_RE); const raw = match ? match[1] : null; const get = (key) => { if (raw === null) return null; const m = raw.match(new RegExp(`^\\s*${key}:\\s*(.*)$`, 'm')); if (!m) return null; let v = m[1].trim(); if (v === '') return null; const q = v[0]; if (q === '"' || q === "'") { const end = v.indexOf(q, 1); if (end !== -1) return v.slice(1, end); // internal '#' preserved v = v.slice(1); // unterminated quote: fall back to the rest } else { v = v.replace(/\s+#.*$/, '').trim(); // unquoted: strip trailing comment } return v === '' ? null : v; }; return { raw, get }; }