Convert Markdown and GitHub Flavoured Markdown to Notion API Blocks and RichText
Martian is a Markdown parser to convert any Markdown content to Notion API block or RichText objects. It uses unified to create a Markdown AST, then converts the AST into Notion objects.
Designed to make using the Notion SDK and API easier.
- All inline elements (italics, bold, strikethrough, inline code, hyperlinks)
- Lists (ordered, unordered, checkboxes)
- All headers (header levels >= 3 are treated as header level 3)
- Code blocks (treated as paragraphs)
- Block quotes (treated as paragraphs)
import {markdownToBlocks, markdownToRichText} from '@instantish/martian';
import type {RichText, Block} from '@notionhq/client/build/src/api-types';
const richText: RichText[] = markdownToRichText(`**Hello _world_**`);
// [
// {
// "type": "text",
// "annotations": {
// "bold": true,
// },
// "text": {
// "content": "Hello "
// }
// },
// {
// "type": "text",
// "annotations": {
// "bold": true,
// "italic": true,
// },
// "text": {
// "content": "world"
// }
// }
// ]
const blocks: Block[] = markdownToBlocks(`
## this is a _heading 2_
* [x] todo list item
`)
// [
// {
// "object": "block",
// "type": "heading_2",
// "heading_2": {
// "text": [
// ...
// {
// "type": "text",
// "annotations": {
// "italic": true
// }
// "text": {
// "content": "heading 2"
// }
// },
// ]
// }
// },
// {
// "object": "block",
// "type": "to_do",
// "to_do": {
// "text": [
// {
// "type": "text",
// "annotations": {
// },
// "text": {
// "content": "todo list item"
// }
// }
// ],
// "checked": true
// }
// }
// ]
Built with 💙 by the team behind Fabric.