Download the PHP package roelmagdaleno/markdown-to-notion-blocks without Composer
On this page you can find all versions of the php package roelmagdaleno/markdown-to-notion-blocks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roelmagdaleno/markdown-to-notion-blocks
More information about roelmagdaleno/markdown-to-notion-blocks
Files in roelmagdaleno/markdown-to-notion-blocks
Package markdown-to-notion-blocks
Short Description Convert markdown to Notion blocks.
License MIT
Homepage https://github.com/roelmagdaleno/markdown-to-notion-blocks
Informations about the package 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, in JSON format, are intended to be sent to the Notion API to create a new page or update an existing one.
It's using thephpleague/commonmark under the hood to parse the Markdown.
Installation
You can install the package via composer:
Size Limits
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
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
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
This package provides a MarkdownToNotionBlocks
class that you can use to convert markdown to Notion blocks in JSON or Array format.
Array
The MarkdownToNotionBlocks::array
static method will return the Notion blocks in array format.
The code above will output the following array:
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.
The code above will output the following JSON:
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:
After applying the transformation, encode the array to JSON and send it to the Notion API.
Supported Notion Blocks
The following Notion blocks are supported by this package:
Each block support rich text properties like bold, italic, strikethrough, underline, and inline code.
Example
The following example shows how to convert a Markdown string to Notion blocks in Array format.