npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@damianflynn/martian

v1.2.6

Published

Converts Markdown to Notion Blocks and RichText

Downloads

7

Readme

Martian: Markdown to Notion Parser

Convert Markdown and GitHub Flavoured Markdown to Notion API Blocks and RichText.

Node.js CI Code Style: Google

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. Notion API version 1.0.

Supported Markdown Elements

  • All inline elements (italics, bold, strikethrough, inline code, hyperlinks, equations)
  • Lists (ordered, unordered, checkboxes) - to any level of depth
  • All headers (header levels >= 3 are treated as header level 3)
  • Code blocks, with language highlighting support
  • Block quotes
  • Tables
  • Equations
  • Images
    • Inline images are extracted from the paragraph and added afterwards (as these are not supported in notion)
    • Image urls are validated, if they are not valid as per the Notion external spec, they will be inserted as text for you to fix manually

Usage

Basic usage:

The package exports two functions, which you can import like this:

// JS
const {markdownToBlocks, markdownToRichText} = require('@tryfabric/martian');
// TS
import {markdownToBlocks, markdownToRichText} from '@tryfabric/martian';

Here are couple of examples with both of them:

markdownToRichText(`**Hello _world_**`);
markdownToBlocks(`
hello _world_ 
*** 
## heading2
* [x] todo
`);

Working with Notion's limits

Sometimes a Markdown input would result in an output that would be rejected by the Notion API: here are some options to deal with that.

An item exceeds the children or character limit

By default, the package will try to resolve these kind of issues by re-distributing the content to multiple blocks: when that's not possible, martian will truncate the output to avoid your request resulting in an error.
If you want to disable this kind of behavior, you can use this option:

const options = {
  notionLimits: {
    truncate: false,
  },
};

markdownToBlocks('input', options);
markdownToRichText('input', options);

Manually handling errors related to Notions's limits

You can set a callback for when one of the resulting items would exceed Notion's limits. Please note that this function will be called regardless of whether the final output will be truncated.

const options = {
  notionLimits: {
    // truncate: true, // by default
    onError: (err: Error) => {
      // Something has appened!
      console.error(err);
    },
  },
};

markdownToBlocks('input', options);
markdownToRichText('input', options);

Working with images

If an image as an invalid URL, the Notion API will reject the whole request: martian prevents this issue by converting images with invalid links into text, so that request are successfull and you can fix the links later.
If you want to disable this kind of behavior, you can use this option:

const options = {
  strictImageUrls: false,
};

Default behavior:

markdownToBlocks('![](InvalidURL)');

strictImageUrls disabled:

markdownToBlocks('![](InvalidURL)', {
  strictImageUrls: false,
});

Non-inline elements when parsing rich text

By default, if the text provided to markdownToRichText would result in one or more non-inline elements, the package will ignore those and only parse paragraphs.
You can make the package throw an error when a non-inline element is detected by setting the nonInline option to 'throw'.

Default behavior:

markdownToRichText('# Header\nAbc', {
  // nonInline: 'ignore', // Default
});

Throw an error:

markdownToRichText('# Header\nAbc', {
  nonInline: 'throw',
});

Built with 💙 by the team behind Fabric.