notion-to-md 2.5.4 → 2.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Souvik Kar Mahapatra
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Souvik Kar Mahapatra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,234 +1,250 @@
1
- <img src="https://imgur.com/WgXdz9r.png" />
2
-
3
- > 💡 For better readability and detailed instructions headover to the [wiki](https://github.com/souvikinator/notion-to-md/wiki)
4
-
5
- # Notion to Markdown
6
-
7
- Convert notion pages, block and list of blocks to markdown (supports nesting) using **[notion-sdk-js](https://github.com/makenotion/notion-sdk-js)**
8
-
9
- > **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
10
-
11
- <a href="https://www.producthunt.com/posts/notion-to-md?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-notion&#0045;to&#0045;md" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=351669&theme=light" alt="notion&#0045;to&#0045;md - Programmatically&#0032;convert&#0032;notion&#0032;pages&#0032;to&#0032;markdown | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
12
-
13
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O1AFCJR)
14
-
15
- ## Todo
16
-
17
- - [x] heading
18
- - [x] images
19
- - [x] quotes
20
- - [x] links
21
- - [x] bullets
22
- - [x] todo
23
- - [x] inline code
24
- - [x] code block
25
- - [x] strikethrough, underline, bold, italic
26
- - [x] nested blocks
27
- - [x] embeds, bookmarks, videos, files (converted to links)
28
- - [x] Simple tables
29
- - [x] toggle
30
- - [x] divider
31
- - [x] equation block (converted to code blocks)
32
- - [x] convert returned markdown object to string (`toMarkdownString()`)
33
- - [x] typescript support
34
- - [x] add tests
35
-
36
- ## Install
37
-
38
- ```Bash
39
- $ npm install notion-to-md
40
- ```
41
-
42
- ## Usage
43
-
44
- > **Note:** Details on methods can be found in [API section](https://github.com/souvikinator/notion-to-md#api)
45
-
46
- ### converting markdown objects to markdown string
47
-
48
- This is how the notion page looks for this example:
49
-
50
- ![Imgur](https://imgur.com/O6bKCmH.png)
51
-
52
- ```js
53
- const { Client } = require("@notionhq/client");
54
- const { NotionToMarkdown } = require("notion-to-md");
55
- // or
56
- // import {NotionToMarkdown} from "notion-to-md";
57
-
58
- const notion = new Client({
59
- auth: "your integration token",
60
- });
61
-
62
- // passing notion client to the option
63
- const n2m = new NotionToMarkdown({ notionClient: notion });
64
-
65
- (async () => {
66
- const mdblocks = await n2m.pageToMarkdown("target_page_id");
67
- const mdString = n2m.toMarkdownString(mdblocks);
68
-
69
- //writing to file
70
- fs.writeFile("test.md", mdString, (err) => {
71
- console.log(err);
72
- });
73
- })();
74
- ```
75
-
76
- **Output:**
77
-
78
- ![output](https://imgur.com/XrUYrZ0.png)
79
-
80
- ### converting page to markdown object
81
-
82
- Example notion page:
83
-
84
- ![Imgur](https://imgur.com/9iqRpBl.png)
85
-
86
- ```js
87
- const { Client } = require("@notionhq/client");
88
- const { NotionToMarkdown } = require("notion-to-md");
89
-
90
- const notion = new Client({
91
- auth: "your integration token",
92
- });
93
-
94
- // passing notion client to the option
95
- const n2m = new NotionToMarkdown({ notionClient: notion });
96
-
97
- (async () => {
98
- // notice second argument, totalPage.
99
- const x = await n2m.pageToMarkdown("target_page_id", 2);
100
- console.log(x);
101
- })();
102
- ```
103
-
104
- **Output:**
105
-
106
- ```json
107
- [
108
- {
109
- "parent": "# heading 1",
110
- "children": []
111
- },
112
- {
113
- "parent": "- bullet 1",
114
- "children": [
115
- {
116
- "parent": "- bullet 1.1",
117
- "children": []
118
- },
119
- {
120
- "parent": "- bullet 1.2",
121
- "children": []
122
- }
123
- ]
124
- },
125
- {
126
- "parent": "- bullet 2",
127
- "children": []
128
- },
129
- {
130
- "parent": "- [ ] check box 1",
131
- "children": [
132
- {
133
- "parent": "- [x] check box 1.2",
134
- "children": []
135
- },
136
- {
137
- "parent": "- [ ] check box 1.3",
138
- "children": []
139
- }
140
- ]
141
- },
142
- {
143
- "parent": "- [ ] checkbox 2",
144
- "children": []
145
- }
146
- ]
147
- ```
148
-
149
- ### converting list of blocks to markdown object
150
-
151
- same notion page as before
152
-
153
- ```js
154
- const { Client } = require("@notionhq/client");
155
- const { NotionToMarkdown } = require("notion-to-md");
156
-
157
- const notion = new Client({
158
- auth: "your integration token",
159
- });
160
-
161
- // passing notion client to the option
162
- const n2m = new NotionToMarkdown({ notionClient: notion });
163
-
164
- (async () => {
165
- // get all blocks in the page
166
- const { results } = await notion.blocks.children.list({
167
- block_id,
168
- });
169
-
170
- //convert to markdown
171
- const x = await n2m.blocksToMarkdown(results);
172
- console.log(x);
173
- })();
174
- ```
175
-
176
- **Output**: same as before
177
-
178
- ### Converting a single block to markdown string
179
-
180
- - only takes a single notion block and returns corresponding markdown string
181
- - nesting is ignored
182
- - depends on @notionhq/client
183
-
184
- ```js
185
- const { NotionToMarkdown } = require("notion-to-md");
186
-
187
- // passing notion client to the option
188
- const n2m = new NotionToMarkdown({ notionClient: notion });
189
-
190
- const result = n2m.blockToMarkdown(block);
191
- console.log(result);
192
- ```
193
-
194
- **result**:
195
-
196
- ```
197
- ![image](https://media.giphy.com/media/Ju7l5y9osyymQ/giphy.gif)
198
- ```
199
-
200
- ## Custom Transformers
201
- You can define your own custom transformer for a notion type, to parse and return your own string.
202
- `setCustomTransformer(type, func)` will overload the parsing for the giving type.
203
-
204
- ```js
205
- const { NotionToMarkdown } = require("notion-to-md");
206
- const n2m = new NotionToMarkdown({ notionClient: notion });
207
- n2m.setCustomTransformer('embed', async (block) => {
208
- const {embed} = block as any;
209
- if (!embed?.url) return '';
210
- return `<figure>
211
- <iframe src="${embed?.url}"></iframe>
212
- <figcaption>${await n2m.blockToMarkdown(embed?.caption)}</figcaption>
213
- </figure>`;
214
- });
215
- const result = n2m.blockToMarkdown(block);
216
- // Result will now parse the `embed` type with your custom function.
217
- ```
218
- **Note** Be aware that `setCustomTransformer` will take only the last function for the given type. You can't set two different transforms for the same type.
219
-
220
- ## Contribution
221
-
222
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
223
- Please make sure to update tests as appropriate.
224
-
225
- ## Contributers
226
-
227
- <a href="https://github.com/souvikinator/notion-to-md/graphs/contributors">
228
- <img src="https://contrib.rocks/image?repo=souvikinator/notion-to-md" />
229
- </a>
230
-
231
-
232
- ## License
233
-
234
- [MIT](https://choosealicense.com/licenses/mit/)
1
+ <img src="https://imgur.com/WgXdz9r.png" />
2
+
3
+ > 💡 For better readability and detailed instructions head over to the [wiki](https://github.com/souvikinator/notion-to-md/wiki).
4
+
5
+ # Notion to Markdown
6
+
7
+ Convert notion pages, block and list of blocks to markdown (supports nesting) using **[notion-sdk-js](https://github.com/makenotion/notion-sdk-js)**
8
+
9
+ > **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
10
+
11
+ <a href="https://www.producthunt.com/posts/notion-to-md?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-notion&#0045;to&#0045;md" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=351669&theme=light" alt="notion&#0045;to&#0045;md - Programmatically&#0032;convert&#0032;notion&#0032;pages&#0032;to&#0032;markdown | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
12
+
13
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O1AFCJR)
14
+
15
+ ## Todo
16
+
17
+ - [x] heading
18
+ - [x] images
19
+ - [x] quotes
20
+ - [x] links
21
+ - [x] bullets
22
+ - [x] todo
23
+ - [x] inline code
24
+ - [x] code block
25
+ - [x] strikethrough, underline, bold, italic
26
+ - [x] nested blocks
27
+ - [x] embeds, bookmarks, videos, files (converted to links)
28
+ - [x] simple tables
29
+ - [x] toggle
30
+ - [x] divider
31
+ - [x] equation block (converted to code blocks)
32
+ - [x] convert returned markdown object to string (`toMarkdownString()`)
33
+ - [x] typescript support
34
+ - [x] add tests
35
+
36
+ ## Install
37
+
38
+ ```Bash
39
+ npm install notion-to-md
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ > **Note:** Details on methods can be found in [API section](https://github.com/souvikinator/notion-to-md#api)
45
+
46
+ ### converting markdown objects to markdown string
47
+
48
+ This is how the notion page looks for this example:
49
+
50
+ ![Imgur](https://imgur.com/O6bKCmH.png)
51
+
52
+ ```js
53
+ const { Client } = require("@notionhq/client");
54
+ const { NotionToMarkdown } = require("notion-to-md");
55
+ // or
56
+ // import {NotionToMarkdown} from "notion-to-md";
57
+
58
+ const notion = new Client({
59
+ auth: "your integration token",
60
+ });
61
+
62
+ // passing notion client to the option
63
+ const n2m = new NotionToMarkdown({ notionClient: notion });
64
+
65
+ (async () => {
66
+ const mdblocks = await n2m.pageToMarkdown("target_page_id");
67
+ const mdString = n2m.toMarkdownString(mdblocks);
68
+
69
+ //writing to file
70
+ fs.writeFile("test.md", mdString, (err) => {
71
+ console.log(err);
72
+ });
73
+ })();
74
+ ```
75
+
76
+ **Output:**
77
+
78
+ ![output](https://imgur.com/XrUYrZ0.png)
79
+
80
+ ### converting page to markdown object
81
+
82
+ Example notion page:
83
+
84
+ ![Imgur](https://imgur.com/9iqRpBl.png)
85
+
86
+ ```js
87
+ const { Client } = require("@notionhq/client");
88
+ const { NotionToMarkdown } = require("notion-to-md");
89
+
90
+ const notion = new Client({
91
+ auth: "your integration token",
92
+ });
93
+
94
+ // passing notion client to the option
95
+ const n2m = new NotionToMarkdown({ notionClient: notion });
96
+
97
+ (async () => {
98
+ // notice second argument, totalPage.
99
+ const x = await n2m.pageToMarkdown("target_page_id", 2);
100
+ console.log(x);
101
+ })();
102
+ ```
103
+
104
+ **Output:**
105
+
106
+ ```json
107
+ [
108
+ {
109
+ "parent": "# heading 1",
110
+ "children": []
111
+ },
112
+ {
113
+ "parent": "- bullet 1",
114
+ "children": [
115
+ {
116
+ "parent": "- bullet 1.1",
117
+ "children": []
118
+ },
119
+ {
120
+ "parent": "- bullet 1.2",
121
+ "children": []
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ "parent": "- bullet 2",
127
+ "children": []
128
+ },
129
+ {
130
+ "parent": "- [ ] check box 1",
131
+ "children": [
132
+ {
133
+ "parent": "- [x] check box 1.2",
134
+ "children": []
135
+ },
136
+ {
137
+ "parent": "- [ ] check box 1.3",
138
+ "children": []
139
+ }
140
+ ]
141
+ },
142
+ {
143
+ "parent": "- [ ] checkbox 2",
144
+ "children": []
145
+ }
146
+ ]
147
+ ```
148
+
149
+ ### converting list of blocks to markdown object
150
+
151
+ same notion page as before
152
+
153
+ ```js
154
+ const { Client } = require("@notionhq/client");
155
+ const { NotionToMarkdown } = require("notion-to-md");
156
+
157
+ const notion = new Client({
158
+ auth: "your integration token",
159
+ });
160
+
161
+ // passing notion client to the option
162
+ const n2m = new NotionToMarkdown({ notionClient: notion });
163
+
164
+ (async () => {
165
+ // get all blocks in the page
166
+ const { results } = await notion.blocks.children.list({
167
+ block_id,
168
+ });
169
+
170
+ //convert to markdown
171
+ const x = await n2m.blocksToMarkdown(results);
172
+ console.log(x);
173
+ })();
174
+ ```
175
+
176
+ **Output**: same as before
177
+
178
+ ### Converting a single block to markdown string
179
+
180
+ - only takes a single notion block and returns corresponding markdown string
181
+ - nesting is ignored
182
+ - depends on @notionhq/client
183
+
184
+ ```js
185
+ const { NotionToMarkdown } = require("notion-to-md");
186
+
187
+ // passing notion client to the option
188
+ const n2m = new NotionToMarkdown({ notionClient: notion });
189
+
190
+ const result = n2m.blockToMarkdown(block);
191
+ console.log(result);
192
+ ```
193
+
194
+ **result**:
195
+
196
+ ```
197
+ ![image](https://media.giphy.com/media/Ju7l5y9osyymQ/giphy.gif)
198
+ ```
199
+
200
+ ## Custom Transformers
201
+
202
+ You can define your own custom transformer for a notion type, to parse and return your own string.
203
+ `setCustomTransformer(type, func)` will overload the parsing for the giving type.
204
+
205
+ ```ts
206
+ const { NotionToMarkdown } = require("notion-to-md");
207
+ const n2m = new NotionToMarkdown({ notionClient: notion });
208
+ n2m.setCustomTransformer("embed", async (block) => {
209
+ const { embed } = block as any;
210
+ if (!embed?.url) return "";
211
+ return `<figure>
212
+ <iframe src="${embed?.url}"></iframe>
213
+ <figcaption>${await n2m.blockToMarkdown(embed?.caption)}</figcaption>
214
+ </figure>`;
215
+ });
216
+ const result = n2m.blockToMarkdown(block);
217
+ // Result will now parse the `embed` type with your custom function.
218
+ ```
219
+
220
+ **Note** Be aware that `setCustomTransformer` will take only the last function for the given type. You can't set two different transforms for the same type.
221
+
222
+ You can also use the default parsing by returning `false` in your custom transformer.
223
+
224
+ ```ts
225
+ // ...
226
+ n2m.setCustomTransformer("embed", async (block) => {
227
+ const { embed } = block as any;
228
+ if (embed?.url?.includes("myspecialurl.com")) {
229
+ return `...`; // some special rendering
230
+ }
231
+ return false; // use default behavior
232
+ });
233
+ const result = n2m.blockToMarkdown(block);
234
+ // Result will now only use custom parser if the embed url matches a specific url
235
+ ```
236
+
237
+ ## Contribution
238
+
239
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
240
+ Please make sure to update tests as appropriate.
241
+
242
+ ## Contributers
243
+
244
+ <a href="https://github.com/souvikinator/notion-to-md/graphs/contributors">
245
+ <img src="https://contrib.rocks/image?repo=souvikinator/notion-to-md" />
246
+ </a>
247
+
248
+ ## License
249
+
250
+ [MIT](https://choosealicense.com/licenses/mit/)
package/build/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./notion-to-md";
1
+ export * from "./notion-to-md";
2
2
  //# sourceMappingURL=index.d.ts.map
package/build/index.js CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./notion-to-md"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./notion-to-md"), exports);
18
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B","sourcesContent":["export * from \"./notion-to-md\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B","sourcesContent":["export * from \"./notion-to-md\";\n"]}