blocksToMarkdown
blocksToMarkdown
converts an array of Notion block objects into a Markdown string.
This is useful for exporting Notion content to Markdown files or displaying it in Markdown editors.
Parameters
Name | Type | Description |
---|---|---|
blocks |
Array |
Array of Notion block objects (from getBlockChildren or mapResponse ). |
Returns
A string
containing the Markdown representation of the blocks.
Supported Block Types
- Paragraphs
- Headings (
#
,##
,###
) - Bulleted lists
- Numbered lists
- Quotes
- Dividers
- To-do lists
- Code blocks (with language)
- Images
- Callouts
- Toggles (as
<details>
blocks) - Tables (GitHub-flavored Markdown)
Example
const blocks = [
{ type: 'heading_1', text: 'Project Overview' },
{ type: 'paragraph', text: 'This is a **bold** paragraph.' },
{ type: 'bulleted_list_item', text: 'First bullet' },
{ type: 'numbered_list_item', text: 'Step one' },
{ type: 'to_do', text: 'Write docs', checked: true },
{ type: 'code', code: 'console.log("Hello, world!");', language: 'js' },
{ type: 'image', url: 'https://example.com/image.png' },
{ type: 'divider' }
];
const markdown = blocksToMarkdown(blocks);
console.log(markdown);
Notes
- Nested blocks (children) are recursively converted.
- Table blocks are rendered as Markdown tables if header and rows are present.
- Unsupported or unknown block types are skipped or rendered as plain text if possible.
Example Output
# Project Overview
This is a **bold** paragraph.
- First bullet
1. Step one
- [x] Write docs
```js
console.log("Hello, world!");
```

---