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

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

Example Output

# Project Overview

This is a **bold** paragraph.

- First bullet
1. Step one
- [x] Write docs

```js
console.log("Hello, world!");
```

![Image](https://example.com/image.png)

---