Skip to content

Commit 189b521

Browse files
committed
create html to notion converter
1 parent bee9e1c commit 189b521

34 files changed

+3601
-187
lines changed

apps/react-pdf/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
"incremental": true,
1414
"types": ["jest", "node"]
1515
},
16-
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "next-env.d.ts"],
16+
"include": [
17+
"**/*.ts",
18+
"**/*.tsx",
19+
"**/*.js",
20+
"**/*.jsx",
21+
"next-env.d.ts",
22+
"next.config.mjs"
23+
],
1724
"exclude": ["node_modules", "jest.config.ts"]
1825
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"extends": [
3+
"../../../.eslintrc.json"
4+
],
5+
"ignorePatterns": [
6+
"!**/*"
7+
],
8+
"overrides": [
9+
{
10+
"files": [
11+
"*.ts",
12+
"*.tsx",
13+
"*.js",
14+
"*.jsx"
15+
],
16+
"rules": {}
17+
},
18+
{
19+
"files": [
20+
"*.ts",
21+
"*.tsx"
22+
],
23+
"rules": {}
24+
},
25+
{
26+
"files": [
27+
"*.js",
28+
"*.jsx"
29+
],
30+
"rules": {}
31+
}
32+
]
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"jsc": {
3+
"target": "es2017",
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"transform": {
10+
"decoratorMetadata": true,
11+
"legacyDecorator": true
12+
},
13+
"keepClassNames": true,
14+
"externalHelpers": true,
15+
"loose": true
16+
},
17+
"module": {
18+
"type": "es6",
19+
"strict": true,
20+
"noInterop": true
21+
},
22+
"sourceMaps": true,
23+
"exclude": [
24+
"jest.config.ts",
25+
".*.spec.tsx?$",
26+
".*.test.tsx?$",
27+
"./src/jest-setup.ts$",
28+
"./**/jest-setup.ts$",
29+
".*.js$"
30+
]
31+
}

libs/notion/html-to-notion-blocks/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# html-to-notion-blocks
2+
3+
[![npm version](https://img.shields.io/npm/v/html-to-notion-blocks.svg)](https://www.npmjs.com/package/html-to-notion-blocks)
4+
[![npm downloads](https://img.shields.io/npm/dm/html-to-notion-blocks.svg)](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
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const config = {
2+
displayName: 'html-to-notion-blocks',
3+
preset: '../../../jest.preset.js',
4+
globals: {
5+
'ts-jest': {
6+
tsconfig: '<rootDir>/tsconfig.spec.json',
7+
useESM: true,
8+
},
9+
},
10+
testEnvironment: 'node',
11+
transform: {
12+
'^.+\\.[tj]sx?$': ['@swc/jest'],
13+
},
14+
transformIgnorePatterns: [],
15+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16+
coverageDirectory: '../../../coverage/libs/html-to-notion-blocks',
17+
extensionsToTreatAsEsm: ['.ts'],
18+
moduleNameMapper: {
19+
'^(\\.{1,2}/.*)\\.js$': '$1',
20+
},
21+
}
22+
23+
export default config
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "html-to-notion-blocks",
3+
"version": "0.0.1",
4+
"license": "GPL-3.0-or-later",
5+
"repository": "https://github.com/TrialAndErrorOrg/parsers",
6+
"author": "Thomas F. K. Jorna <[email protected]>",
7+
"type": "module",
8+
"description": "Transform HTML to Notion blocks",
9+
"keywords": [
10+
"unified",
11+
"abstract",
12+
"syntax",
13+
"tree",
14+
"ast"
15+
]
16+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "notion-html-to-notion-blocks",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/notion/html-to-notion-blocks/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nrwl/js:swc",
9+
"outputs": [
10+
"{options.outputPath}"
11+
],
12+
"options": {
13+
"outputPath": "dist/libs/notion/html-to-notion-blocks",
14+
"tsConfig": "libs/notion/html-to-notion-blocks/tsconfig.lib.json",
15+
"packageJson": "libs/notion/html-to-notion-blocks/package.json",
16+
"main": "libs/notion/html-to-notion-blocks/src/index.ts",
17+
"assets": [
18+
"libs/notion/html-to-notion-blocks/*.md"
19+
]
20+
}
21+
},
22+
"lint": {
23+
"executor": "@nrwl/linter:eslint",
24+
"outputs": [
25+
"{options.outputFile}"
26+
],
27+
"options": {
28+
"lintFilePatterns": [
29+
"libs/notion/html-to-notion-blocks/**/*.ts"
30+
]
31+
}
32+
},
33+
"test": {
34+
"executor": "@nrwl/jest:jest",
35+
"outputs": [
36+
"{workspaceRoot}/coverage/{projectRoot}"
37+
],
38+
"options": {
39+
"jestConfig": "libs/notion/html-to-notion-blocks/jest.config.ts",
40+
"passWithNoTests": true
41+
}
42+
}
43+
},
44+
"tags": []
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/html-to-notion-blocks'

0 commit comments

Comments
 (0)