serializeMarkdown module provides utilities for parsing and serializing Markdown/MDX content with support for syntax highlighting, heading extraction, and GitHub-flavored Markdown.
Import
Functions
serializeMarkdown
next-mdx-remote, with automatic heading extraction.
Parameters:
markdown(Compatible) - The Markdown/MDX content to serialize. Can be a string, Buffer, or VFile.
Promise<{ source, headings }>- An object containing:source- Serialized MDX content ready for renderingheadings- Array of extracted headings with their text, depth, and slug
- GitHub-flavored Markdown support (tables, strikethrough, task lists, etc.)
- Automatic heading slug generation
- Syntax highlighting with
github-dark-dimmedtheme - Frontmatter parsing
remark-gfm- GitHub-flavored Markdown supportrehype-slug- Automatic heading ID generationrehype-pretty-code- Syntax highlighting for code blocksrehypeExtractHeadings- Custom plugin to extract heading metadata
serializeMarkdownSafe
markdown(Compatible) - The Markdown/MDX content to serialize
Promise<{ source, headings }>- Same asserializeMarkdown, but guaranteed not to throw
Usage Example:
Types
Heading
Real-World Examples
Anime Synopsis Rendering
Artist Information Rendering
Custom Page with Table of Contents
Announcement Feed
Syntax Highlighting
Code blocks are automatically syntax highlighted usingrehype-pretty-code with the github-dark-dimmed theme.
Supported Languages:
All languages supported by Shiki, including:
- JavaScript/TypeScript
- JSX/TSX
- Python
- Rust
- Go
- And many more
GitHub-Flavored Markdown
The following GFM features are supported:- Tables
- Strikethrough (
~~text~~) - Task lists (
- [ ]and- [x]) - Autolinks
- Footnotes
See Also
- next-mdx-remote - Server-side MDX rendering
- rehype-pretty-code - Syntax highlighting
- remark-gfm - GitHub-flavored Markdown plugin