1.0.0-rc.1 • Published 1 year ago

@kerwanp/notion-renderer v1.0.0-rc.1

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

@kerwan/notion-renderer

Transform Notion Rich Text into HTML.

PRs Welcome Commitizen friendly License

@kerwanp/notion-renderer

Managed with

🔨 Install🚀 Get started🔧 ExtendContributeLicense

⚠ Pre-release

This project is currently in pre-release, you can use it but some features are lacking and core components are still able to change.

Do not hesitate to open an issue to provide your feedback, report bugs and to propose new features.

🔨 Install

$ npm install @kerwanp/notion-renderer
$ yarn add @kerwanp/notion-renderer

🚀 Get started

import { Client } from '@notionhq/notion';
import { NotionRenderer } from '@kerwanp/notion-renderer';

const client = new Client({
  auth: process.env.NOTION_TOKEN,
});

const renderer = new NotionRenderer();

const { results } = await client.blocks.children.list({
  block_id: '<page_id>',
});

const html = renderer.render(...results);

🔧 Extend

Custom renderer

You can create custom renderers to handle custom Notion plugins and override existing blocks.

import { NotionRenderer, createBlockRenderer } from '@syneki/notion-renderer';

const paragraphRenderer = createBlockRenderer<ParagraphBlockObjectResponse>(
  'paragraph',
  (data, renderer) => {
    return `<p>${renderer.render(...data.paragraph.rich_text)}</p>`;
  }
);

const renderer = new NotionRenderer({
  renderers: [paragraphRenderer],
});

Contributing

I'd love for you to contribute to this project. You can request new features by creating an issue, or submit a pull request with your contribution.

Licence

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

1.0.0-rc.2

1 year ago

1.0.0-rc.1

1 year ago