|
| 1 | +# html-to-notion-blocks |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/html-to-notion-blocks) |
| 4 | +[](https://www.npmjs.com/package/html-to-notion-blocks) |
| 5 | + |
| 6 | +Transform HTML to Notion blocks |
| 7 | + |
| 8 | +## Contents |
| 9 | + |
| 10 | +- [html-to-notion-blocks](#html-to-notion-blocks) |
| 11 | + - [Contents](#contents) |
| 12 | + - [What is this?](#what-is-this) |
| 13 | + - [When should I use this?](#when-should-i-use-this) |
| 14 | + - [Install](#install) |
| 15 | + - [Use](#use) |
| 16 | + - [API](#api) |
| 17 | + - [`htmlToNotion(html: string, options?: Options): NotionBlock[]`](#htmltonotionhtml-string-options-options-notionblock) |
| 18 | + - [Parameters](#parameters) |
| 19 | + - [`html`](#html) |
| 20 | + - [`options`](#options) |
| 21 | + - [Security](#security) |
| 22 | + - [Related](#related) |
| 23 | + - [License](#license) |
| 24 | + |
| 25 | +## What is this? |
| 26 | + |
| 27 | +A small library that transforms HTML to Notion blocks. It is based on [rehype-to-notion][rehype-to-notion]. |
| 28 | + |
| 29 | +## When should I use this? |
| 30 | + |
| 31 | +You want a simple way to convert HTML to Notion blocks. If you want to control the conversion process, you should use [rehype-to-notion][rehype-to-notion] instead. |
| 32 | + |
| 33 | +## Install |
| 34 | + |
| 35 | +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+). |
| 36 | + |
| 37 | +```sh |
| 38 | +pnpm add html-to-notion-blocks |
| 39 | +# or |
| 40 | +# yarn add html-to-notion-blocks |
| 41 | +# or |
| 42 | +# npm install html-to-notion-blocks |
| 43 | +``` |
| 44 | + |
| 45 | +## Use |
| 46 | + |
| 47 | +```ts |
| 48 | +import { htmlToNotion } from 'html-to-notion-blocks' |
| 49 | + |
| 50 | +const html = '<p>Hello world!</p>' |
| 51 | + |
| 52 | +const notionBlocks = htmlToNotion(html) |
| 53 | + |
| 54 | +console.log(notionBlocks) |
| 55 | +// [ |
| 56 | +// { |
| 57 | +// object: 'block', |
| 58 | +// type: 'paragraph', |
| 59 | +// paragraph: { |
| 60 | +// text: [ |
| 61 | +// { |
| 62 | +// type: 'text', |
| 63 | +// text: { |
| 64 | +// content: 'Hello world!', |
| 65 | +// link: null |
| 66 | +// }, |
| 67 | +// annotations: { |
| 68 | +// bold: false, |
| 69 | +// italic: false, |
| 70 | +// strikethrough: false, |
| 71 | +// underline: false, |
| 72 | +// code: false, |
| 73 | +// color: 'default' |
| 74 | +// }, |
| 75 | +// plain_text: 'Hello world!', |
| 76 | +// href: null |
| 77 | +// } |
| 78 | +// ] |
| 79 | +// } |
| 80 | +// } |
| 81 | +// ] |
| 82 | +``` |
| 83 | + |
| 84 | +## API |
| 85 | + |
| 86 | +### `htmlToNotion(html: string, options?: Options): NotionBlock[]` |
| 87 | + |
| 88 | +Transform HTML to Notion blocks. |
| 89 | + |
| 90 | +#### Parameters |
| 91 | + |
| 92 | +##### `html` |
| 93 | + |
| 94 | +Type: `string` |
| 95 | + |
| 96 | +The HTML to transform. |
| 97 | + |
| 98 | +##### `options` |
| 99 | + |
| 100 | +Type: `Options` |
| 101 | + |
| 102 | +Options for the transformation. |
| 103 | + |
| 104 | +See [rehype-to-notion][rehype-to-notion] for the full list of options. |
| 105 | + |
| 106 | +## Security |
| 107 | + |
| 108 | +Use of `html-to-notion-blocks` 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][rehype-sanitize]. |
| 109 | + |
| 110 | +## Related |
| 111 | + |
| 112 | +- [rehype-to-notion][rehype-to-notion] |
| 113 | + — Transform HTML to Notion blocks |
| 114 | +- [rehype-sanitize][rehype-sanitize] |
| 115 | +- [rehype][rehype] |
| 116 | + — HTML processor powered by plugins part of the [unified][unified] collective |
| 117 | + |
| 118 | +## License |
| 119 | + |
| 120 | +GPL-3.0-or-later © Thomas F. K. Jorna |
| 121 | + |
| 122 | +[unified]: https://unifiedjs.com |
| 123 | +[unifiedgh]: https://github.com/unifiedjs/unified |
| 124 | +[xast-from-xml]: https://github.com/syntax-tree/xast-util-from-xml |
| 125 | +[rehype]: https://github.com/rehypejs/rehype |
| 126 | +[rejour]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour |
| 127 | +[rejour-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-parse |
| 128 | +[rejour-stringify]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-stringify |
| 129 | +[rejour-move-abstract]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-move-abstract |
| 130 | +[rejour-meta]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-meta |
| 131 | +[rejour-relatex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-relatex |
| 132 | +[relatex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex |
| 133 | +[relatex-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/relatex-parse |
| 134 | +[jast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jast |
| 135 | +[jast-util-to-texast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jast-util-to-texast |
| 136 | +[jastscript]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jastscript |
| 137 | +[texast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/texast |
| 138 | +[texast-util-to-latex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/texast-util-to-latex |
| 139 | +[hast]: https://github.com/syntax-tree/hast |
| 140 | +[xast]: https://github.com/syntax-tree/xast |
| 141 | +[mdast]: https://github.com/syntax-tree/mdast |
| 142 | +[mdast-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown |
| 143 | +[latex-utensils]: https://github.com/tamuratak/latex-utensils |
| 144 | +[latexjs]: https://github.com/latexjs/latexjs |
| 145 | +[reoff]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff |
| 146 | +[reoff-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff/reoff-parse |
| 147 | +[reoff-rejour]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff/reoff-rejour |
| 148 | +[ooxast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/ooxast/ooxast |
| 149 | +[ooxast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/ooxast/ooxast-util-to-jast |
| 150 | +[rehype-to-notion]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/notion/rehype-to-notion |
| 151 | +[html-to-notion-blocks]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/notion/html-to-notion-blocks |
0 commit comments