Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

470 B
Raw Blame
/** Display leading YAML metadata as code without changing the stored document. */
export function splitMarkdownFrontmatter(
  markdown: string,
): { rawFrontmatter: string; body: string } | null {
  const match =
    /^(?:\uFEFF)?---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/.exec(
      markdown,
    )
  if (!match) return null
  return {
    rawFrontmatter: match[0].replace(/^\uFEFF/, '').trimEnd(),
    body: markdown.slice(match[0].length),
  }
}