markdownToBlocks

markdownToBlocks is a utility function that converts a markdown string into an array of Notion block objects.
This allows you to easily transform markdown content into a format suitable for appendBlockChildren or page creation in Notion.

Parameters

Name Type Description
markdown string The markdown text to convert.

Returns

An Array of Notion block objects representing the parsed markdown structure.
Each block can be used directly with appendBlockChildren or similar NotionBridge functions.

Supported Markdown Features

Example



const markdown = `
# Project Overview

This is a **bold** paragraph with a [link](https://example.com).

- [x] Write docs
- [ ] Add more features

## Code Example

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

| Name   | Status    |
|--------|-----------|
| Task 1 | Complete  |
| Task 2 | Incomplete|
`;

const blocks = markdownToBlocks(markdown);
await notion.appendBlockChildren('parentBlockId', blocks);

Notes

Example Output

[
  {
    "object": "block",
    "type": "heading_1",
    "heading_1": {
      "rich_text": [
        { "type": "text", "text": { "content": "Project Overview" } }
      ]
    }
  },
  {
    "object": "block",
    "type": "paragraph",
    "paragraph": {
      "rich_text": [
        { "type": "text", "text": { "content": "This is a " } },
        { "type": "text", "text": { "content": "bold" }, "annotations": { "bold": true } },
        { "type": "text", "text": { "content": " paragraph with a " } },
        { "type": "text", "text": { "content": "link" }, "href": "https://example.com" },
        { "type": "text", "text": { "content": "." } }
      ]
    }
  },
  {
    "object": "block",
    "type": "to_do",
    "to_do": {
      "rich_text": [
        { "type": "text", "text": { "content": "Write docs" } }
      ],
      "checked": true
    }
  },
  {
    "object": "block",
    "type": "to_do",
    "to_do": {
      "rich_text": [
        { "type": "text", "text": { "content": "Add more features" } }
      ],
      "checked": false
    }
  },
  {
    "object": "block",
    "type": "heading_2",
    "heading_2": {
      "rich_text": [
        { "type": "text", "text": { "content": "Code Example" } }
      ]
    }
  },
  {
    "object": "block",
    "type": "code",
    "code": {
      "rich_text": [
        { "type": "text", "text": { "content": "console.log(\"Hello, world!\");" } }
      ],
      "language": "javascript"
    }
  },
  {
    "object": "block",
    "type": "table",
    "table": {
      "table_width": 2,
      "has_column_header": true,
      "has_row_header": false,
      "children": [
        {
          "object": "block",
          "type": "table_row",
          "table_row": {
            "cells": [
              [{ "type": "text", "text": { "content": "Name" } }],
              [{ "type": "text", "text": { "content": "Status" } }]
            ]
          }
        },
        {
          "object": "block",
          "type": "table_row",
          "table_row": {
            "cells": [
              [{ "type": "text", "text": { "content": "Task 1" } }],
              [{ "type": "text", "text": { "content": "Complete" } }]
            ]
          }
        },
        {
          "object": "block",
          "type": "table_row",
          "table_row": {
            "cells": [
              [{ "type": "text", "text": { "content": "Task 2" } }],
              [{ "type": "text", "text": { "content": "Incomplete" } }]
            ]
          }
        }
      ]
    }
  }
]