Kate Bartolo

mdxParser

mdxParser<T>(rawContent): object

Parses a raw Markdown or MDX string into frontmatter and body content.

Intended for use with remotely fetched .md or .mdx content before passing it to the MDX renderer.

Type Parameters

T

T extends Record<string, unknown> = Record<string, unknown>

Parameters

rawContent

string

The raw Markdown or MDX string to parse.

Returns

object

An object containing:

  • frontmatter — the parsed YAML frontmatter as a plain object
  • content — the body of the document with frontmatter stripped

content

content: string

frontmatter

frontmatter: T

Example

ts
const raw = await fetch('https://example.com/post.mdx').then(r => r.text());
const { frontmatter, content } = mdxParser(raw);