PHPackages                             roelmagdaleno/markdown-to-notion-blocks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. roelmagdaleno/markdown-to-notion-blocks

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

roelmagdaleno/markdown-to-notion-blocks
=======================================

Convert markdown to Notion blocks.

1.2.2(1y ago)2111↓100%1[1 PRs](https://github.com/roelmagdaleno/markdown-to-notion-blocks/pulls)MITPHPPHP ^8.0

Since Sep 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/roelmagdaleno/markdown-to-notion-blocks)[ Packagist](https://packagist.org/packages/roelmagdaleno/markdown-to-notion-blocks)[ Docs](https://github.com/roelmagdaleno/markdown-to-notion-blocks)[ RSS](/packages/roelmagdaleno-markdown-to-notion-blocks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Markdown to Notion Blocks
=========================

[](#markdown-to-notion-blocks)

This package allows you to convert markdown to Notion blocks in JSON or Array format.

The generated [Notion blocks](https://developers.notion.com/reference/block), in JSON format, are intended to be sent to the [Notion API](https://developers.notion.com/docs/getting-started) to create a new page or update an existing one.

It's using [thephpleague/commonmark](https://github.com/thephpleague/commonmark) under the hood to parse the Markdown.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require roelmagdaleno/markdown-to-notion-blocks
```

Size Limits
-----------

[](#size-limits)

### Maximum Blocks

[](#maximum-blocks)

The Notion API only accepts a maximum of 100 blocks per request. So, this package will always return an array, in chunks, of 100 blocks.

You'll have to send each chunk to the Notion API separately.

### Text Content

[](#text-content)

The Notion API only accepts a maximum of 2000 characters per text content. If the text content is more than 2000 characters, the package will split them into multiple rich text objects.

### Rich Text

[](#rich-text)

The Notion API only accepts a maximum of 100 rich text objects per block. If the rich text objects are more than 100, the package will split them into multiple blocks.

Usage
-----

[](#usage)

This package provides a `MarkdownToNotionBlocks` class that you can use to convert markdown to Notion blocks in JSON or Array format.

### Array

[](#array)

The `MarkdownToNotionBlocks::array` static method will return the Notion blocks in array format.

```
use RoelMR\MarkdownToNotionBlocks\MarkdownToNotionBlocks;

$markdown = '# Hello, world!';
$notionBlocks = MarkdownToNotionBlocks::array($markdown);

print_r($notionBlocks);
```

The code above will output the following array:

```
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [object] => block
                    [type] => heading_1
                    [heading_1] => Array
                        (
                            [rich_text] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => text
                                            [text] => Array
                                                (
                                                    [content] => Hello, world!
                                                    [link] =>
                                                )
                                            [annotations] => Array
                                                (
                                                    [bold] =>
                                                    [italic] =>
                                                    [strikethrough] =>
                                                    [underline] =>
                                                    [code] =>
                                                    [color] => default
                                                )
                                        )
                                )
                            [color] => default
                            [is_toggleable] =>
                        )
                )
        )
)

```

### JSON

[](#json)

The `MarkdownToNotionBlocks::json` static method will return the Notion blocks in JSON format.

Note

Since the Notion blocks are returned in chunks of 100, the JSON output might not be valid for the Notion API. The JSON output is useful for debugging purposes or send it from the server to the client.

```
use RoelMR\MarkdownToNotionBlocks\MarkdownToNotionBlocks;

$markdown = '# Hello, world!';
$notionBlocks = MarkdownToNotionBlocks::json($markdown);

echo $notionBlocks;
```

The code above will output the following JSON:

```
[
  [
    {
      "object": "block",
      "type": "heading_1",
      "heading_1": {
        "rich_text": [
          {
            "type": "text",
            "text": {
              "content": "Hello, world!",
              "link": null
            },
            "annotations": {
              "bold": false,
              "italic": false,
              "strikethrough": false,
              "underline": false,
              "code": false,
              "color": "default"
            }
          }
        ],
        "color": "default",
        "is_toggleable": false
      }
    }
  ]
]
```

Transform Output
----------------

[](#transform-output)

If you want to transform the output before sending to the Notion API, you can use the `MarkdownToNotionBlocks::array` method to get the Notion blocks in array format and then apply your transformations.

For example, by default each Notion block has a `color` property set to `default`. If you want to change the color of the heading to `red`, you can do the following:

```
use RoelMR\MarkdownToNotionBlocks\MarkdownToNotionBlocks;

$markdown = '# Hello, world!';

$notionBlocks = MarkdownToNotionBlocks::array($markdown);

$notionBlocks[0]['heading_1']['rich_text'][0]['text']['content'] = 'My heading changed.';
$notionBlocks[0]['heading_1']['color'] = 'red';

echo json_encode($notionBlocks);
```

After applying the transformation, encode the array to JSON and send it to the [Notion API](https://developers.notion.com/docs/getting-started).

Supported Notion Blocks
-----------------------

[](#supported-notion-blocks)

The following Notion blocks are supported by this package:

- [Bulleted List](https://developers.notion.com/reference/block#bulleted-list-item)
- [Callout](https://developers.notion.com/reference/block#callout)
- [Code](https://developers.notion.com/reference/block#code)
- [Headings](https://developers.notion.com/reference/block#headings)
- [Numbered List](https://developers.notion.com/reference/block#numbered-list-item)
- [Paragraph](https://developers.notion.com/reference/block#paragraph)
- [Quote](https://developers.notion.com/reference/block#quote)
- [To do](https://developers.notion.com/reference/block#to-do)

Each block support [rich text](https://developers.notion.com/reference/rich-text) properties like bold, italic, strikethrough, underline, and inline code.

Example
-------

[](#example)

The following example shows how to convert a Markdown string to Notion blocks in Array format.

```
use RoelMR\MarkdownToNotionBlocks\MarkdownToNotionBlocks;

$markdown = file_get_contents($file_path);

$notion_blocks = MarkdownToNotionBlocks::array($markdown);

if (!$notion_blocks) {
    return false;
}

$notion_db_id = '101c7zs03d0680e6aa1cf27a0e61e8f4';

foreach ($notion_blocks as $notion_block) {
    append_blocks_to_notion_page($notion_db_id, $notion_block);
}
```

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

5

Last Release

516d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b2f8632cbecc6f9a25cddf3861bb17d54c1d228502bb30e9f60020a1dfd76f7?d=identicon)[roelmagdaleno](/maintainers/roelmagdaleno)

---

Top Contributors

[![roelmagdaleno](https://avatars.githubusercontent.com/u/3928004?v=4)](https://github.com/roelmagdaleno "roelmagdaleno (38 commits)")

---

Tags

markdownnotionnotion-blocksparsermarkdownblocksnotion

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/roelmagdaleno-markdown-to-notion-blocks/health.svg)

```
[![Health](https://phpackages.com/badges/roelmagdaleno-markdown-to-notion-blocks/health.svg)](https://phpackages.com/packages/roelmagdaleno-markdown-to-notion-blocks)
```

###  Alternatives

[daux/daux.io

Documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly

825191.0k1](/packages/daux-dauxio)[bookdown/bookdown

Provides DocBook-like rendering of Markdown files.

8257.6k16](/packages/bookdown-bookdown)[torchlight/torchlight-commonmark

A Commonmark extension for Torchlight, the syntax highlighting API.

29256.6k6](/packages/torchlight-torchlight-commonmark)[maglnet/magl-markdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

22178.2k4](/packages/maglnet-magl-markdown)[zoon/commonmark-ext-youtube-iframe

Extension for league/commonmark to replace youtube link with iframe

12275.9k1](/packages/zoon-commonmark-ext-youtube-iframe)[spatie/commonmark-wire-navigate

Add a wire:navigate attribute to links rendered in Markdown

1010.7k](/packages/spatie-commonmark-wire-navigate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
