Overview
The Notion Parse module converts Notion’s block-based content format into Markdown and HTML suitable for static site generation. It handles rich text formatting, nested blocks, tables, media embeds, and more.Core Functions
parseBlocks()
Converts an array of Notion blocks to a Markdown string.
Array of Notion block objects (typically from
getBlock())Markdown/HTML string representation of the blocks
parse()
Recursively parses a single Notion block (with children) to Markdown.
A Notion block object with optional children array
Indentation depth (used internally for nested blocks)
Markdown/HTML representation of the block and its children
Rich Text Functions
parseRichTextBlock()
Converts Notion rich text to Markdown with inline formatting.
Array of Notion rich text items
Block-level color (applied to entire text)
Markdown string with HTML tags for formatting
- Bold:
<b>text</b> - Italic:
<i>text</i> - Strikethrough:
<s>text</s> - Underline:
<u>text</u> - Code:
<code>text</code> - Links:
[text](url) - Colors:
<span class="!text-{color}-500">text</span>
richTextToPlainText()
Extracts plain text from Notion rich text (removes all formatting).
Array of Notion rich text items
Plain text string without any formatting
parseColor()
Converts Notion color values to Tailwind CSS classes.
Notion color value (e.g., ‘red’, ‘blue’, ‘orange_background’)
The text to wrap in a colored span
HTML span with Tailwind color class
| Notion Color | Tailwind Class |
|---|---|
gray | !text-gray-500 |
brown | !text-stone-500 |
orange | !text-orange-500 |
yellow | !text-yellow-500 |
green | !text-green-500 |
blue | !text-blue-500 |
purple | !text-purple-500 |
pink | !text-pink-500 |
red | !text-red-500 |
gray_background | !bg-gray-200 |
orange_background | !bg-orange-200 |
| (etc.) | (background variants use -200 suffix) |
Heading Functions
parseHeading()
Converts a Notion heading block to Markdown.
The heading’s rich text content
Heading level (1-3 for H1-H3)
Child blocks (rendered after heading)
List Functions
parseListItem()
Converts a list item block to Markdown.
The list item’s rich text content
List marker (
"- " for bullets, "1. " for numbered, "- [ ] " for todos)Nested list items
Supported Block Types
Text Blocks
- Paragraph: Plain text with formatting
- Heading 1-3: Markdown headings (
#,##,###) - Quote: Blockquotes with
>prefix - Callout: Rendered as code blocks (
```)
Lists
- Bulleted List:
-prefix - Numbered List:
1.prefix (all items use1.) - To-Do List:
- [ ]or- [x]checkboxes
Code & Equations
- Code Block: Fenced code blocks with language
- Equation: Raw LaTeX expressions
Media
- Image: Astro
<Image>component with width/height - Video: HTML5
<video>element - Audio: HTML5
<audio>element - PDF:
<object>embed with fallback - File: Ignored (not rendered)
Embeds & Links
- Embed: Link with caption
- Bookmark/Link Preview: Blockquote with link
Advanced Blocks
- Table: HTML
<table>with header support - Toggle:
<details>element - Divider: Horizontal rule (
___) - Table of Contents: Ignored (not rendered)
Unsupported Blocks
These blocks return empty strings:breadcrumbcolumn_list,columnlink_to_pagetemplatesynced_blockchild_page,child_databaseunsupported
Property Parsing
parseProperty()
Converts a Notion page property to a string value.
A Notion page property object
String representation of the property value
| Type | Output |
|---|---|
title | Plain text |
rich_text | Plain text |
number | Number as string |
url | URL string |
checkbox | "true" or "false" |
email | Email address |
date | ISO date string |
last_edited_time | ISO timestamp |
created_time | ISO timestamp |
multi_select | Comma-separated tags |
formula (string) | Formula result |
| others | "unsupported" |
Special Formatting
HTML Escaping
All< characters in text are escaped to < to prevent HTML injection:
Indentation
Child blocks are indented using theINDENT constant (" " - 2 spaces):
Line Endings
The module usesEOL ("\n") for consistent line breaks across platforms.
Examples
Complete Page Conversion
Table Rendering
Custom Colored Text
Type Definitions
Related Modules
- Notion CMS - Retrieve blocks from Notion
- Notion Download - Use parser for MDX generation
- HTML Utility - Template literal helper
Source Reference
File:src/lib/notion-parse.ts:1-350
Dependencies:
@notionhq/client- Notion API types./notion-types- Custom type definitions./html- HTML template helper./constants- EOL and INDENT constants