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

rehype-notion

v0.1.3

Published

Plugin for `rehype` to turn HTML into Notion blocks

Downloads

26

Readme

Note This repository is automatically generated from the main parser monorepo. Please submit any issues or pull requests there.

rehype-notion

npm version npm downloads

npm version npm downloads

Plugin for rehype to turn HTML into Notion blocks

Contents

What is this?

A compiler plugin for rehype that transforms a [hast][hast] syntax tree into Notion blocks.

When should I use this?

You want to convert HTML to Notion blocks but want control over the conversion process. If you just want to convert HTML to Notion blocks, you should use html-to-notion-blocks instead.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install as

pnpm add rehype-notion
# or with yarn
# yarn add rehype-notion
# or with npm
# npm install rehype-notion

Use

import { unified } from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeNotion from 'rehype-notion'

const html = `
  <h1>Heading</h1>
  <p>Paragraph</p>
`

const notionBlocks = unified().use(rehypeParse).use(rehypeNotion).processSync(html).result

// or with options and async

const vfile = await unified()
  .use(parse)
  .use(
    rehypeNotion,
    //  {
    //    hastToMdastOptions: {...}
    //    mdastToMarkdownOptions: {...}
    //    markdownToNotionOptions: {...}
    //  }
  )
  .process(html).result

const notionBlocks = vfile.result

console.log(notionBlocks)
// [
//   {
//     object: 'block',
//     type: 'heading_1',
//     heading_1: {
//       rich_text: [
//         {
//           annotations: {
//             bold: false,
//             italic: false,
//             strikethrough: false,
//             underline: false,
//             code: false,
//             color: 'default'
//           },
//           text: {
//             content: 'Heading',
//             link: null
//           }
//           type: 'text',
//         }
//       ]
//     }
//   },
//   {
//     object: 'block',
//     type: 'paragraph',
//     paragraph: {
//       rich_text: [
//         {
//           annotations: {
//             bold: false,
//             italic: false,
//             strikethrough: false,
//             underline: false,
//             code: false,
//             color: 'default'
//           },
//           text: {
//             content: 'Paragraph',
//             link: null
//           }
//           type: 'text'
//         }
//       ]
//     }
//   }
// ]

API


default()

A plugin is a function. It configures the processor and in turn can receive options. Plugins can configure processors by interacting with parsers and compilers (at this.Parser or this.Compiler) or by specifying how the syntax tree is handled (by returning a Transformer).

Signature

default(this: Processor<void, Root, Root, BlockObjectRequest[]> | Processor<void, Comment, Comment, BlockObjectRequest[]> | Processor<void, DocType, DocType, BlockObjectRequest[]> | Processor<void, Element, Element, BlockObjectRequest[]> | Processor<void, Text, Text, BlockObjectRequest[]>, ...settings: [Options] | [void] | []): void;

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | this | Processor<void, Root, Root, BlockObjectRequest[]> | Processor<void, Comment, Comment, BlockObjectRequest[]> | Processor<void, DocType, DocType, BlockObjectRequest[]> | Processor<void, Element, Element, BlockObjectRequest[]> | Processor<void, Text, Text, BlockObjectRequest[]> | - | | ...settings | [Options] | [void] | [] | Configuration for plugin. Plugins typically receive one options object, but could receive other and more values. Users can also pass a boolean instead of settings: true (to turn a plugin on) or false (to turn a plugin off). When a plugin is turned off, it won’t be called. When creating your own plugins, please accept only a single object! It allows plugins to be reconfigured and it helps users to know that every plugin accepts one options object. |

Returns

void

Plugins can return a Transformer to specify how the syntax tree is handled.

Defined in: node_modules/.pnpm/[email protected]/node_modules/unified/index.d.ts:531


Options

Properties

hastToMdastOptions?

Options

Defined in: src/lib/rehype-notion.ts:29

markdownToNotionOptions?

BlocksOptions

Defined in: src/lib/rehype-notion.ts:31

mdastToMarkdownOptions?

MdastToMarkdownOptions

Defined in: src/lib/rehype-notion.ts:30


Block

AppendBlockChildrenParameters["children"][number]

Defined in: src/lib/rehype-notion.ts:13

Security

Use of rehypeNotion can open you up to a [cross-site scripting (XSS)][xss] attack. If you are processing user input, be sure to use a HTML sanitizer, such as rehype-sanitize.

Related

License

GPL-3.0-or-later © Thomas F. K. Jorna