notion-to-md 2.5.6 → 2.7.0

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/README.md CHANGED
@@ -1,37 +1,32 @@
1
- <img src="https://imgur.com/WgXdz9r.png" />
2
1
 
3
- > 💡 For better readability and detailed instructions head over to the [wiki](https://github.com/souvikinator/notion-to-md/wiki).
2
+ <!--
3
+ 💡 For better readability and detailed instructions head over to the [wiki](https://github.com/souvikinator/notion-to-md/wiki).
4
+ -->
5
+ <h1 align="center">
6
+ <br>
7
+ <img src="https://imgur.com/WgXdz9r.png" alt="notion-to-md banner" width="750" />
8
+ <br>
9
+ <b>Notion-to-MD</b>
10
+ <br>
11
+ <sub><sup><b>(Notion to Markdown)</b></sup></sub>
12
+ <br>
13
+ </h1>
4
14
 
5
- # Notion to Markdown
15
+ <p align="center">
16
+ Notion-to-MD is a Node.js package that allows you to convert Notion pages to Markdown format.
17
+ </p>
18
+ <p align="center">
19
+ Convert notion pages, block and list of blocks to markdown (supports nesting) using <a href="https://github.com/makenotion/notion-sdk-js">notion-sdk-js</a>
20
+ </p>
21
+ <p align="center">
22
+ <img src="https://img.shields.io/github/stars/souvikinator/notion-to-md?style=for-the-badge"
23
+ alt="">
24
+ <a href="https://www.producthunt.com/products/notion-to-md?utm_source=badge-follow&utm_medium=badge&utm_souce=badge-notion&#0045;to&#0045;md" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/follow.svg?product_id=486574&theme=light&size=small" alt="notion&#0045;to&#0045;md - Programmatically&#0032;convert&#0032;notion&#0032;pages&#0032;to&#0032;markdown | Product Hunt" style="width: 86px; height: 32px;" width="86" height="32" /></a>
25
+
26
+ </p>
6
27
 
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
28
 
9
- > **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
10
29
 
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
30
 
36
31
  ## Install
37
32
 
@@ -40,18 +35,19 @@ npm install notion-to-md
40
35
  ```
41
36
 
42
37
  ## Usage
38
+ > **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
39
+ > Details on methods can be found in [API section](https://github.com/souvikinator/notion-to-md#api)
43
40
 
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
41
+ ## converting markdown objects to markdown string
47
42
 
48
43
  This is how the notion page looks for this example:
49
44
 
50
- ![Imgur](https://imgur.com/O6bKCmH.png)
45
+ <img src="https://imgur.com/O6bKCmH.png" width="500" />
51
46
 
52
- ```js
47
+ ```javascript
53
48
  const { Client } = require("@notionhq/client");
54
49
  const { NotionToMarkdown } = require("notion-to-md");
50
+ const fs = require('fs');
55
51
  // or
56
52
  // import {NotionToMarkdown} from "notion-to-md";
57
53
 
@@ -65,23 +61,88 @@ const n2m = new NotionToMarkdown({ notionClient: notion });
65
61
  (async () => {
66
62
  const mdblocks = await n2m.pageToMarkdown("target_page_id");
67
63
  const mdString = n2m.toMarkdownString(mdblocks);
64
+ console.log(mdString);
65
+ })();
66
+ ```
67
+
68
+ **Output:**
69
+
70
+ <img src="https://imgur.com/XrUYrZ0.png" width="500" />
71
+
72
+ ## Save content to file
73
+
74
+ **parent page content:**
68
75
 
76
+ <img src="https://user-images.githubusercontent.com/64456160/236519171-b32d8f62-1e2c-4897-a302-ae0dd85adef9.png" width="500" />
77
+
78
+ **child page content:**
79
+
80
+ <img src="https://user-images.githubusercontent.com/64456160/236519726-37513735-db0c-4643-9c89-f8deb355a6d3.png" width="500" />
81
+
82
+ ### Saving page to a file
83
+
84
+ Simply saving `mdString` from above code to a file does the work like so
85
+
86
+ ```javascript
69
87
  //writing to file
70
88
  fs.writeFile("test.md", mdString, (err) => {
71
89
  console.log(err);
72
90
  });
91
+ ```
92
+ > ⚠️ **Note**: with this the `child_page` content is merged in the same file.
93
+
94
+ **Output:**
95
+
96
+ <img src="https://user-images.githubusercontent.com/64456160/236520621-fc1d328f-51e3-4e39-a529-7ef1b9f75ab3.png" width="500" />
97
+
98
+ ### Saving `child_page` to separate file
99
+
100
+ `NotionToMarkdown` takes second argument, `config`
101
+
102
+
103
+ ```javascript
104
+ const { Client } = require("@notionhq/client");
105
+ const { NotionToMarkdown } = require("notion-to-md");
106
+ const fs = require('fs');
107
+ // or
108
+ // import {NotionToMarkdown} from "notion-to-md";
109
+
110
+ const notion = new Client({
111
+ auth: "your integration token",
112
+ config:{
113
+ saveChildPage: true, //default: false
114
+ saveToDir: "path/to/output/dir", //default: current directory
115
+ }
116
+ });
117
+
118
+ // passing notion client to the option
119
+ const n2m = new NotionToMarkdown({ notionClient: notion });
120
+
121
+ (async () => {
122
+ const mdblocks = await n2m.pageToMarkdown("target_page_id");
123
+ const mdString = n2m.toMarkdownString(mdblocks);
124
+
125
+ // writing parent page content to file
126
+ // where the child pages will be saved
127
+ // the child page will be linked to the parent page
128
+ fs.writeFile("test.md", mdString, (err) => {
129
+ console.log(err);
130
+ });
73
131
  })();
74
132
  ```
75
133
 
76
134
  **Output:**
77
135
 
78
- ![output](https://imgur.com/XrUYrZ0.png)
136
+ > ⚠️ **Note:** make sure to save parent page in the same directory as that of child page
137
+ > for the link from parent to child page to work.
79
138
 
80
- ### converting page to markdown object
139
+ <img src="https://user-images.githubusercontent.com/64456160/236521464-fd137be9-ade1-444b-86fc-562d5ad06568.png" width="500" />
140
+ <img src="https://user-images.githubusercontent.com/64456160/236521541-c08d6062-9229-4429-96d5-78ab699600a1.png" width="500" />
81
141
 
82
- Example notion page:
142
+ ## converting page to markdown object
83
143
 
84
- ![Imgur](https://imgur.com/9iqRpBl.png)
144
+ **Example notion page:**
145
+ <img src="https://imgur.com/9iqRpBl.png" width="500" />
85
146
 
86
147
  ```js
87
148
  const { Client } = require("@notionhq/client");
@@ -146,9 +207,7 @@ const n2m = new NotionToMarkdown({ notionClient: notion });
146
207
  ]
147
208
  ```
148
209
 
149
- ### converting list of blocks to markdown object
150
-
151
- same notion page as before
210
+ ## converting list of blocks to markdown object
152
211
 
153
212
  ```js
154
213
  const { Client } = require("@notionhq/client");
@@ -175,7 +234,7 @@ const n2m = new NotionToMarkdown({ notionClient: notion });
175
234
 
176
235
  **Output**: same as before
177
236
 
178
- ### Converting a single block to markdown string
237
+ ## Converting a single block to markdown string
179
238
 
180
239
  - only takes a single notion block and returns corresponding markdown string
181
240
  - nesting is ignored
@@ -1,9 +1,11 @@
1
- import { Annotations, CustomTransformer, ListBlockChildrenResponseResult, ListBlockChildrenResponseResults, MdBlock, NotionToMarkdownOptions } from './types';
1
+ import { Annotations, CustomTransformer, ListBlockChildrenResponseResult, ListBlockChildrenResponseResults, MdBlock, NotionToMarkdownOptions, MdStringObject } from "./types";
2
2
  /**
3
3
  * Converts a Notion page to Markdown.
4
4
  */
5
5
  export declare class NotionToMarkdown {
6
6
  private notionClient;
7
+ private config;
8
+ private targetPage;
7
9
  private customTransformers;
8
10
  constructor(options: NotionToMarkdownOptions);
9
11
  setCustomTransformer(type: string, transformer: CustomTransformer): NotionToMarkdown;
@@ -11,9 +13,9 @@ export declare class NotionToMarkdown {
11
13
  * Converts Markdown Blocks to string
12
14
  * @param {MdBlock[]} mdBlocks - Array of markdown blocks
13
15
  * @param {number} nestingLevel - Defines max depth of nesting
14
- * @returns {string} - Returns markdown string
16
+ * @returns {MdStringObject} - Returns markdown string with child pages separated
15
17
  */
16
- toMarkdownString(mdBlocks?: MdBlock[], nestingLevel?: number): string;
18
+ toMarkdownString(mdBlocks?: MdBlock[], pageIdentifier?: string, nestingLevel?: number): MdStringObject;
17
19
  /**
18
20
  * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
19
21
  * @param {string} id - notion page id (not database id)
@@ -1 +1 @@
1
- {"version":3,"file":"notion-to-md.d.ts","sourceRoot":"","sources":["../src/notion-to-md.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,+BAA+B,EAC/B,gCAAgC,EAChC,OAAO,EACP,uBAAuB,EAGxB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,kBAAkB,CAAoC;gBAClD,OAAO,EAAE,uBAAuB;IAI5C,oBAAoB,CAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,GAC7B,gBAAgB;IAKnB;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,GAAE,OAAO,EAAO,EAAE,YAAY,GAAE,MAAU,GAAG,MAAM;IAuC5E;;;;;OAKG;IACG,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,MAAM,GAAG,IAAW,GAC9B,OAAO,CAAC,OAAO,EAAE,CAAC;IAgBrB;;;;;;OAMG;IACG,gBAAgB,CACpB,MAAM,CAAC,EAAE,gCAAgC,EACzC,SAAS,GAAE,MAAM,GAAG,IAA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MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM;CAsBlE"}
@@ -32,6 +32,11 @@ const notion_1 = require("./utils/notion");
32
32
  class NotionToMarkdown {
33
33
  constructor(options) {
34
34
  this.notionClient = options.notionClient;
35
+ const defaultConfig = {
36
+ separateChildPage: false,
37
+ };
38
+ this.targetPage = "";
39
+ this.config = { ...defaultConfig, ...options.config };
35
40
  this.customTransformers = {};
36
41
  }
37
42
  setCustomTransformer(type, transformer) {
@@ -42,39 +47,75 @@ class NotionToMarkdown {
42
47
  * Converts Markdown Blocks to string
43
48
  * @param {MdBlock[]} mdBlocks - Array of markdown blocks
44
49
  * @param {number} nestingLevel - Defines max depth of nesting
45
- * @returns {string} - Returns markdown string
50
+ * @returns {MdStringObject} - Returns markdown string with child pages separated
46
51
  */
47
- toMarkdownString(mdBlocks = [], nestingLevel = 0) {
48
- let mdString = "";
52
+ toMarkdownString(mdBlocks = [], pageIdentifier = "parent", nestingLevel = 0) {
53
+ let mdOutput = {};
49
54
  mdBlocks.forEach((mdBlocks) => {
55
+ // NOTE: toggle in the child blocks logic
56
+ // adding a toggle check prevents duplicate
57
+ // rendering of toggle title
50
58
  // process parent blocks
51
- if (mdBlocks.parent) {
59
+ if (mdBlocks.parent &&
60
+ mdBlocks.type !== "toggle" &&
61
+ mdBlocks.type !== "child_page") {
52
62
  if (mdBlocks.type !== "to_do" &&
53
63
  mdBlocks.type !== "bulleted_list_item" &&
54
64
  mdBlocks.type !== "numbered_list_item") {
65
+ // initialize if key doesn't exist
66
+ mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
55
67
  // add extra line breaks non list blocks
56
- mdString += `\n${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n\n`;
68
+ mdOutput[pageIdentifier] += `\n${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n\n`;
57
69
  }
58
70
  else {
59
- mdString += `${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n`;
71
+ // initialize if key doesn't exist
72
+ mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
73
+ mdOutput[pageIdentifier] += `${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n`;
60
74
  }
61
75
  }
62
76
  // process child blocks
63
77
  if (mdBlocks.children && mdBlocks.children.length > 0) {
64
78
  if (mdBlocks.type === "synced_block" ||
65
- mdBlocks.type === "child_page") {
66
- let mdstr = this.toMarkdownString(mdBlocks.children);
67
- // console.log(mdstr);
68
- mdString += mdstr;
79
+ mdBlocks.type === "column_list" ||
80
+ mdBlocks.type === "column") {
81
+ let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier);
82
+ // mdOutput[pageIdentifier] += mdstr[pageIdentifier];
83
+ mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
84
+ Object.keys(mdstr).forEach((key) => {
85
+ if (mdOutput[key]) {
86
+ mdOutput[key] + mdstr[key];
87
+ }
88
+ else {
89
+ mdOutput[key] = mdstr[key];
90
+ }
91
+ });
92
+ mdOutput[pageIdentifier] += mdstr[pageIdentifier];
93
+ // mdOutput = { ...mdOutput, ...mdstr };
94
+ }
95
+ else if (mdBlocks.type === "child_page") {
96
+ const childPageTitle = mdBlocks.parent;
97
+ let mdstr = this.toMarkdownString(mdBlocks.children, childPageTitle);
98
+ if (this.config.separateChildPage) {
99
+ // console.log("<<", mdOutput, mdstr);
100
+ mdOutput = { ...mdOutput, ...mdstr };
101
+ // console.log(">>", mdOutput, "\n\n");
102
+ }
103
+ else {
104
+ mdOutput[pageIdentifier] += mdstr[childPageTitle];
105
+ }
106
+ }
107
+ else if (mdBlocks.type === "toggle") {
108
+ // convert children md object to md string
109
+ const toggle_children_md_string = this.toMarkdownString(mdBlocks.children);
110
+ mdOutput[pageIdentifier] += md.toggle(mdBlocks.parent, toggle_children_md_string["parent"]);
69
111
  }
70
112
  else {
71
- let mdstr = this.toMarkdownString(mdBlocks.children, nestingLevel + 1);
72
- mdString += mdstr;
73
- // console.log(mdstr);
113
+ let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier, nestingLevel + 1);
114
+ mdOutput[pageIdentifier] += mdstr["parent"];
74
115
  }
75
116
  }
76
117
  });
77
- return mdString;
118
+ return mdOutput;
78
119
  }
79
120
  /**
80
121
  * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
@@ -86,9 +127,9 @@ class NotionToMarkdown {
86
127
  if (!this.notionClient) {
87
128
  throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
88
129
  }
130
+ this.targetPage = id;
89
131
  const blocks = await (0, notion_1.getBlockChildren)(this.notionClient, id, totalPage);
90
132
  const parsedData = await this.blocksToMarkdown(blocks);
91
- // console.log(JSON.stringify(parsedData, null, 4));
92
133
  return parsedData;
93
134
  }
94
135
  /**
@@ -106,11 +147,7 @@ class NotionToMarkdown {
106
147
  return mdBlocks;
107
148
  for (let i = 0; i < blocks.length; i++) {
108
149
  let block = blocks[i];
109
- if ("has_children" in block &&
110
- block.has_children &&
111
- block.type !== "column_list" &&
112
- block.type !== "toggle" &&
113
- block.type !== "callout") {
150
+ if ("has_children" in block && block.has_children) {
114
151
  // Get children of this block.
115
152
  let child_blocks = await (0, notion_1.getBlockChildren)(this.notionClient, block.id, totalPage);
116
153
  // Push this block to mdBlocks.
@@ -126,13 +163,12 @@ class NotionToMarkdown {
126
163
  continue;
127
164
  }
128
165
  let tmp = await this.blockToMarkdown(block);
129
- // console.log(block);
130
166
  mdBlocks.push({
131
167
  // @ts-ignore
132
168
  type: block.type,
133
169
  blockId: block.id,
134
170
  parent: tmp,
135
- children: []
171
+ children: [],
136
172
  });
137
173
  }
138
174
  return mdBlocks;
@@ -143,7 +179,6 @@ class NotionToMarkdown {
143
179
  * @returns {string} corresponding markdown string of the passed block
144
180
  */
145
181
  async blockToMarkdown(block) {
146
- var _a;
147
182
  if (typeof block !== "object" || !("type" in block))
148
183
  return "";
149
184
  let parsedData = "";
@@ -170,7 +205,7 @@ class NotionToMarkdown {
170
205
  case "divider": {
171
206
  return md.divider();
172
207
  }
173
- case 'equation': {
208
+ case "equation": {
174
209
  return md.equation(block.equation.expression);
175
210
  }
176
211
  case "video":
@@ -197,8 +232,6 @@ class NotionToMarkdown {
197
232
  case "embed":
198
233
  case "link_preview":
199
234
  case "link_to_page":
200
- case "child_page":
201
- case "child_database":
202
235
  {
203
236
  let blockContent;
204
237
  let title = type;
@@ -212,24 +245,30 @@ class NotionToMarkdown {
212
245
  block.link_to_page.type === "page_id") {
213
246
  blockContent = { url: block.link_to_page.page_id };
214
247
  }
215
- if (type === "child_page") {
216
- blockContent = { url: block.id };
217
- title = block.child_page.title;
218
- }
219
- if (type === "child_database") {
220
- blockContent = { url: block.id };
221
- title = block.child_database.title || "child_database";
222
- }
223
248
  if (blockContent)
224
249
  return md.link(title, blockContent.url);
225
250
  }
226
251
  break;
252
+ case "child_page":
253
+ {
254
+ let pageTitle = block.child_page.title;
255
+ if (this.config.separateChildPage) {
256
+ return pageTitle;
257
+ }
258
+ return md.heading2(pageTitle);
259
+ }
260
+ break;
261
+ case "child_database":
262
+ {
263
+ let pageTitle = block.child_database.title || `child_database`;
264
+ return pageTitle;
265
+ }
266
+ break;
227
267
  case "table": {
228
268
  const { id, has_children } = block;
229
269
  let tableArr = [];
230
270
  if (has_children) {
231
271
  const tableRows = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
232
- // console.log(">>", tableRows);
233
272
  let rowsPromise = tableRows === null || tableRows === void 0 ? void 0 : tableRows.map(async (row) => {
234
273
  const { type } = row;
235
274
  const cells = row[type]["cells"];
@@ -243,47 +282,12 @@ class NotionToMarkdown {
243
282
  paragraph: { rich_text: cell },
244
283
  }));
245
284
  const cellStringArr = await Promise.all(cellStringPromise);
246
- // console.log("~~", cellStringArr);
247
285
  tableArr.push(cellStringArr);
248
- // console.log(tableArr);
249
286
  });
250
287
  await Promise.all(rowsPromise || []);
251
288
  }
252
289
  return md.table(tableArr);
253
290
  }
254
- // NOTE: column_list is parent of columns
255
- case "column_list": {
256
- const { id, has_children } = block;
257
- if (!has_children)
258
- return "";
259
- const column_list_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
260
- let column_list_promise = column_list_children.map(async (column) => await this.blockToMarkdown(column));
261
- let column_list = await Promise.all(column_list_promise);
262
- return column_list.join("\n\n");
263
- }
264
- case "column": {
265
- const { id, has_children } = block;
266
- if (!has_children)
267
- return "";
268
- const column_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
269
- let column_children_mdBlocks = await this.blocksToMarkdown(column_children);
270
- let column_string = this.toMarkdownString(column_children_mdBlocks);
271
- return column_string;
272
- }
273
- case "toggle": {
274
- const { id, has_children } = block;
275
- const toggle_summary = (_a = block.toggle.rich_text[0]) === null || _a === void 0 ? void 0 : _a.plain_text;
276
- // empty toggle
277
- if (!has_children) {
278
- return md.toggle(toggle_summary);
279
- }
280
- const toggle_children_object = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
281
- // parse children blocks to md object
282
- const toggle_children = await this.blocksToMarkdown(toggle_children_object);
283
- // convert children md object to md string
284
- const toggle_children_md_string = this.toMarkdownString(toggle_children);
285
- return md.toggle(toggle_summary, toggle_children_md_string);
286
- }
287
291
  // Rest of the types
288
292
  // "paragraph"
289
293
  // "heading_1"
@@ -301,8 +305,6 @@ class NotionToMarkdown {
301
305
  // "callout"
302
306
  // "breadcrumb"
303
307
  // "table_of_contents"
304
- // "column_list"
305
- // "column"
306
308
  // "link_to_page"
307
309
  // "audio"
308
310
  // "unsupported"
@@ -311,7 +313,7 @@ class NotionToMarkdown {
311
313
  // @ts-ignore
312
314
  let blockContent = block[type].text || block[type].rich_text || [];
313
315
  blockContent.map((content) => {
314
- if (content.type === 'equation') {
316
+ if (content.type === "equation") {
315
317
  parsedData += md.inlineEquation(content.equation.expression);
316
318
  return;
317
319
  }
@@ -1 +1 @@
1
- {"version":3,"file":"notion-to-md.js","sourceRoot":"","sources":["../src/notion-to-md.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,+CAA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,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEvE,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACjD,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,WAAW,CAAC,MAAM;gBAAE,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,WAAW,CAAC,aAAa;gBAAE,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC7D,IAAI,WAAW,CAAC,SAAS;gBAAE,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACtD;QAED,OAAO,aAAa,GAAG,IAAI,GAAG,cAAc,CAAC;IAC/C,CAAC;CACF;AAjfD,4CAifC","sourcesContent":["import { Client } from '@notionhq/client';\n\nimport {\n Annotations,\n CustomTransformer,\n ListBlockChildrenResponseResult,\n ListBlockChildrenResponseResults,\n MdBlock,\n NotionToMarkdownOptions,\n Equation,\n Text,\n} from './types';\nimport * as md from './utils/md';\nimport { getBlockChildren } from './utils/notion';\n\n/**\n * Converts a Notion page to Markdown.\n */\nexport class NotionToMarkdown {\n private notionClient: Client;\n private customTransformers: Record<string, CustomTransformer>;\n constructor(options: NotionToMarkdownOptions) {\n this.notionClient = options.notionClient;\n this.customTransformers = {};\n }\n setCustomTransformer(\n type: string,\n transformer: CustomTransformer\n ): NotionToMarkdown {\n this.customTransformers[type] = transformer;\n\n return this;\n }\n /**\n * Converts Markdown Blocks to string\n * @param {MdBlock[]} mdBlocks - Array of markdown blocks\n * @param {number} nestingLevel - Defines max depth of nesting\n * @returns {string} - Returns markdown string\n */\n toMarkdownString(mdBlocks: MdBlock[] = [], nestingLevel: number = 0): string {\n let mdString = \"\";\n mdBlocks.forEach((mdBlocks) => {\n // process parent blocks\n if (mdBlocks.parent) {\n if (\n mdBlocks.type !== \"to_do\" &&\n mdBlocks.type !== \"bulleted_list_item\" &&\n mdBlocks.type !== \"numbered_list_item\"\n ) {\n // add extra line breaks non list blocks\n mdString += `\\n${md.addTabSpace(mdBlocks.parent, nestingLevel)}\\n\\n`;\n } else {\n mdString += `${md.addTabSpace(mdBlocks.parent, nestingLevel)}\\n`;\n }\n }\n\n // process child blocks\n if (mdBlocks.children && mdBlocks.children.length > 0) {\n if (\n mdBlocks.type === \"synced_block\" ||\n mdBlocks.type === \"child_page\"\n ) {\n let mdstr = this.toMarkdownString(mdBlocks.children);\n // console.log(mdstr);\n mdString += mdstr;\n } else {\n let mdstr = this.toMarkdownString(\n mdBlocks.children,\n nestingLevel + 1\n );\n mdString += mdstr;\n // console.log(mdstr);\n }\n }\n });\n return mdString;\n }\n\n /**\n * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks\n * @param {string} id - notion page id (not database id)\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100 (Default=null)\n * @returns {Promise<MdBlock[]>} - List of markdown blocks\n */\n async pageToMarkdown(\n id: string,\n totalPage: number | null = null\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n\n const blocks = await getBlockChildren(this.notionClient, id, totalPage);\n\n const parsedData = await this.blocksToMarkdown(blocks);\n\n // console.log(JSON.stringify(parsedData, null, 4));\n\n return parsedData;\n }\n\n /**\n * Converts list of Notion Blocks to Markdown Blocks\n * @param {ListBlockChildrenResponseResults | undefined} blocks - List of notion blocks\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100\n * @param {MdBlock[]} mdBlocks - Defines max depth of nesting\n * @returns {Promise<MdBlock[]>} - Array of markdown blocks with their children\n */\n async blocksToMarkdown(\n blocks?: ListBlockChildrenResponseResults,\n totalPage: number | null = null,\n mdBlocks: MdBlock[] = []\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n\n if (!blocks) return mdBlocks;\n\n for (let i = 0; i < blocks.length; i++) {\n let block = blocks[i];\n if (\n \"has_children\" in block &&\n block.has_children &&\n block.type !== \"column_list\" &&\n block.type !== \"toggle\" &&\n block.type !== \"callout\"\n ) {\n // Get children of this block.\n let child_blocks = await getBlockChildren(\n this.notionClient,\n block.id,\n totalPage\n );\n\n // Push this block to mdBlocks.\n mdBlocks.push({\n type: block.type,\n blockId: block.id,\n parent: await this.blockToMarkdown(block),\n children: [],\n });\n\n // Recursively call blocksToMarkdown to get children of this block.\n let l = mdBlocks.length;\n await this.blocksToMarkdown(\n child_blocks,\n totalPage,\n mdBlocks[l - 1].children\n );\n continue;\n }\n let tmp = await this.blockToMarkdown(block);\n // console.log(block);\n mdBlocks.push({\n // @ts-ignore\n type: block.type,\n blockId: block.id,\n parent: tmp,\n children: []\n });\n }\n return mdBlocks;\n }\n\n /**\n * Converts a Notion Block to a Markdown Block\n * @param {ListBlockChildrenResponseResult} block - single notion block\n * @returns {string} corresponding markdown string of the passed block\n */\n async blockToMarkdown(block: ListBlockChildrenResponseResult) {\n if (typeof block !== \"object\" || !(\"type\" in block)) return \"\";\n\n let parsedData = \"\";\n const { type } = block;\n if (type in this.customTransformers && !!this.customTransformers[type]) {\n const customTransformerValue = await this.customTransformers[type](block);\n if (!!customTransformerValue || customTransformerValue === \"\")\n return customTransformerValue;\n }\n\n switch (type) {\n case \"image\":\n {\n let blockContent = block.image;\n const image_caption_plain = blockContent.caption\n .map((item) => item.plain_text)\n .join(\"\");\n const image_type = blockContent.type;\n if (image_type === \"external\")\n return md.image(image_caption_plain, blockContent.external.url);\n if (image_type === \"file\")\n return md.image(image_caption_plain, blockContent.file.url);\n }\n break;\n\n case \"divider\": {\n return md.divider();\n }\n\n case 'equation': {\n return md.equation(block.equation.expression);\n }\n\n case \"video\":\n case \"file\":\n case \"pdf\":\n {\n let blockContent;\n if (type === \"video\") blockContent = block.video;\n if (type === \"file\") blockContent = block.file;\n if (type === \"pdf\") blockContent = block.pdf;\n if (blockContent) {\n const file_type = blockContent.type;\n if (file_type === \"external\")\n return md.link(\"image\", blockContent.external.url);\n if (file_type === \"file\")\n return md.link(\"image\", blockContent.file.url);\n }\n }\n break;\n\n case \"bookmark\":\n case \"embed\":\n case \"link_preview\":\n case \"link_to_page\":\n case \"child_page\":\n case \"child_database\":\n {\n let blockContent;\n let title: string = type;\n if (type === \"bookmark\") blockContent = block.bookmark;\n if (type === \"embed\") blockContent = block.embed;\n if (type === \"link_preview\") blockContent = block.link_preview;\n if (\n type === \"link_to_page\" &&\n block.link_to_page.type === \"page_id\"\n ) {\n blockContent = { url: block.link_to_page.page_id };\n }\n\n if (type === \"child_page\") {\n blockContent = { url: block.id };\n title = block.child_page.title;\n }\n\n if (type === \"child_database\") {\n blockContent = { url: block.id };\n title = block.child_database.title || \"child_database\";\n }\n\n if (blockContent) return md.link(title, blockContent.url);\n }\n break;\n\n case \"table\": {\n const { id, has_children } = block;\n let tableArr: string[][] = [];\n if (has_children) {\n const tableRows = await getBlockChildren(this.notionClient, id, 100);\n // console.log(\">>\", tableRows);\n let rowsPromise = tableRows?.map(async (row) => {\n const { type } = row as any;\n const cells = (row as any)[type][\"cells\"];\n\n /**\n * this is more like a hack since matching the type text was\n * difficult. So converting each cell to paragraph type to\n * reuse the blockToMarkdown function\n */\n let cellStringPromise = cells.map(\n async (cell: any) =>\n await this.blockToMarkdown({\n type: \"paragraph\",\n paragraph: { rich_text: cell },\n } as ListBlockChildrenResponseResult)\n );\n\n const cellStringArr = await Promise.all(cellStringPromise);\n // console.log(\"~~\", cellStringArr);\n tableArr.push(cellStringArr);\n // console.log(tableArr);\n });\n await Promise.all(rowsPromise || []);\n }\n return md.table(tableArr);\n }\n\n // NOTE: column_list is parent of columns\n case \"column_list\": {\n const { id, has_children } = block;\n\n if (!has_children) return \"\";\n\n const column_list_children = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n let column_list_promise = column_list_children.map(\n async (column) => await this.blockToMarkdown(column)\n );\n\n let column_list: string[] = await Promise.all(column_list_promise);\n\n return column_list.join(\"\\n\\n\");\n }\n\n case \"column\": {\n const { id, has_children } = block;\n if (!has_children) return \"\";\n\n const column_children = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n let column_children_mdBlocks = await this.blocksToMarkdown(\n column_children\n );\n\n let column_string = this.toMarkdownString(column_children_mdBlocks);\n\n return column_string;\n }\n\n case \"toggle\": {\n const { id, has_children } = block;\n\n const toggle_summary = block.toggle.rich_text[0]?.plain_text;\n\n // empty toggle\n if (!has_children) {\n return md.toggle(toggle_summary);\n }\n\n const toggle_children_object = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n // parse children blocks to md object\n const toggle_children = await this.blocksToMarkdown(\n toggle_children_object\n );\n\n // convert children md object to md string\n const toggle_children_md_string =\n this.toMarkdownString(toggle_children);\n\n return md.toggle(toggle_summary, toggle_children_md_string);\n }\n // Rest of the types\n // \"paragraph\"\n // \"heading_1\"\n // \"heading_2\"\n // \"heading_3\"\n // \"bulleted_list_item\"\n // \"numbered_list_item\"\n // \"quote\"\n // \"to_do\"\n // \"template\"\n // \"synced_block\"\n // \"child_page\"\n // \"child_database\"\n // \"code\"\n // \"callout\"\n // \"breadcrumb\"\n // \"table_of_contents\"\n // \"column_list\"\n // \"column\"\n // \"link_to_page\"\n // \"audio\"\n // \"unsupported\"\n\n default: {\n // In this case typescript is not able to index the types properly, hence ignoring the error\n // @ts-ignore\n let blockContent = block[type].text || block[type].rich_text || [];\n blockContent.map((content: Text | Equation) => {\n if (content.type === 'equation') {\n parsedData += md.inlineEquation(content.equation.expression);\n return;\n }\n \n const annotations = content.annotations;\n let plain_text = content.plain_text;\n\n plain_text = this.annotatePlainText(plain_text, annotations);\n\n if (content[\"href\"])\n plain_text = md.link(plain_text, content[\"href\"]);\n\n parsedData += plain_text;\n });\n }\n }\n\n switch (type) {\n case \"code\":\n {\n parsedData = md.codeBlock(parsedData, block[type].language);\n }\n break;\n\n case \"heading_1\":\n {\n parsedData = md.heading1(parsedData);\n }\n break;\n\n case \"heading_2\":\n {\n parsedData = md.heading2(parsedData);\n }\n break;\n\n case \"heading_3\":\n {\n parsedData = md.heading3(parsedData);\n }\n break;\n\n case \"quote\":\n {\n parsedData = md.quote(parsedData);\n }\n break;\n\n case \"callout\":\n {\n const { id, has_children } = block;\n let callout_string = \"\";\n\n if (!has_children) {\n return md.callout(parsedData, block[type].icon);\n }\n\n const callout_children_object = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n // // parse children blocks to md object\n const callout_children = await this.blocksToMarkdown(\n callout_children_object\n );\n\n callout_string += `${parsedData}\\n`;\n callout_children.map((child) => {\n callout_string += `${child.parent}\\n\\n`;\n });\n\n parsedData = md.callout(callout_string.trim(), block[type].icon);\n }\n break;\n\n case \"bulleted_list_item\":\n {\n parsedData = md.bullet(parsedData);\n }\n break;\n\n case \"numbered_list_item\":\n {\n parsedData = md.bullet(parsedData, block.numbered_list_item.number);\n }\n break;\n\n case \"to_do\":\n {\n parsedData = md.todo(parsedData, block.to_do.checked);\n }\n break;\n }\n\n return parsedData;\n }\n\n /**\n * Annoate text using provided annotations\n * @param {string} text - String to be annotated\n * @param {Annotations} annotations - Annotation object of a notion block\n * @returns {string} - Annotated text\n */\n annotatePlainText(text: string, annotations: Annotations): string {\n // if text is all spaces, don't annotate\n if (text.match(/^\\s*$/)) return text;\n\n const leadingSpaceMatch = text.match(/^(\\s*)/);\n const trailingSpaceMatch = text.match(/(\\s*)$/);\n\n const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : \"\";\n const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : \"\";\n\n text = text.trim();\n\n if (text !== \"\") {\n if (annotations.code) text = md.inlineCode(text);\n if (annotations.bold) text = md.bold(text);\n if (annotations.italic) text = md.italic(text);\n if (annotations.strikethrough) text = md.strikethrough(text);\n if (annotations.underline) text = md.underline(text);\n }\n\n return leading_space + text + trailing_space;\n }\n}\n"]}
1
+ {"version":3,"file":"notion-to-md.js","sourceRoot":"","sources":["../src/notion-to-md.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,+CAAiC;AACjC,2CAAkD;AAElD;;GAEG;AACH,MAAa,gBAAgB;IAM3B,YAAY,OAAgC;QAC1C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,MAAM,aAAa,GAAyB;YAC1C,iBAAiB,EAAE,KAAK;SACzB,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACtD,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;IAC/B,CAAC;IAED,oBAAoB,CAClB,IAAY,EACZ,WAA8B;QAE9B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CACd,WAAsB,EAAE,EACxB,iBAAyB,QAAQ,EACjC,eAAuB,CAAC;QAExB,IAAI,QAAQ,GAAmB,EAAE,CAAC;QAElC,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5B,yCAAyC;YACzC,2CAA2C;YAC3C,4BAA4B;YAE5B,wBAAwB;YACxB,IACE,QAAQ,CAAC,MAAM;gBACf,QAAQ,CAAC,IAAI,KAAK,QAAQ;gBAC1B,QAAQ,CAAC,IAAI,KAAK,YAAY,EAC9B;gBACA,IACE,QAAQ,CAAC,IAAI,KAAK,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I,CAAC,KAAK,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QAErC,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhD,MAAM,aAAa,GAAG,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,cAAc,GAAG,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEvE,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACjD,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,WAAW,CAAC,MAAM;gBAAE,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,WAAW,CAAC,aAAa;gBAAE,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC7D,IAAI,WAAW,CAAC,SAAS;gBAAE,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACtD;QAED,OAAO,aAAa,GAAG,IAAI,GAAG,cAAc,CAAC;IAC/C,CAAC;CACF;AAjfD,4CAifC","sourcesContent":["import { Client } from \"@notionhq/client\";\n\nimport {\n Annotations,\n CustomTransformer,\n ListBlockChildrenResponseResult,\n ListBlockChildrenResponseResults,\n MdBlock,\n NotionToMarkdownOptions,\n Equation,\n Text,\n ConfigurationOptions,\n MdStringObject,\n} from \"./types\";\nimport * as md from \"./utils/md\";\nimport { getBlockChildren } from \"./utils/notion\";\n\n/**\n * Converts a Notion page to Markdown.\n */\nexport class NotionToMarkdown {\n private notionClient: Client;\n private config: ConfigurationOptions;\n private targetPage: string;\n private customTransformers: Record<string, CustomTransformer>;\n\n constructor(options: NotionToMarkdownOptions) {\n this.notionClient = options.notionClient;\n const defaultConfig: ConfigurationOptions = {\n separateChildPage: false,\n };\n this.targetPage = \"\";\n this.config = { ...defaultConfig, ...options.config };\n this.customTransformers = {};\n }\n\n setCustomTransformer(\n type: string,\n transformer: CustomTransformer\n ): NotionToMarkdown {\n this.customTransformers[type] = transformer;\n\n return this;\n }\n\n /**\n * Converts Markdown Blocks to string\n * @param {MdBlock[]} mdBlocks - Array of markdown blocks\n * @param {number} nestingLevel - Defines max depth of nesting\n * @returns {MdStringObject} - Returns markdown string with child pages separated\n */\n toMarkdownString(\n mdBlocks: MdBlock[] = [],\n pageIdentifier: string = \"parent\",\n nestingLevel: number = 0\n ): MdStringObject {\n let mdOutput: MdStringObject = {};\n\n mdBlocks.forEach((mdBlocks) => {\n // NOTE: toggle in the child blocks logic\n // adding a toggle check prevents duplicate\n // rendering of toggle title\n\n // process parent blocks\n if (\n mdBlocks.parent &&\n mdBlocks.type !== \"toggle\" &&\n mdBlocks.type !== \"child_page\"\n ) {\n if (\n mdBlocks.type !== \"to_do\" &&\n mdBlocks.type !== \"bulleted_list_item\" &&\n mdBlocks.type !== \"numbered_list_item\"\n ) {\n // initialize if key doesn't exist\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n // add extra line breaks non list blocks\n mdOutput[pageIdentifier] += `\\n${md.addTabSpace(\n mdBlocks.parent,\n nestingLevel\n )}\\n\\n`;\n } else {\n // initialize if key doesn't exist\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n mdOutput[pageIdentifier] += `${md.addTabSpace(\n mdBlocks.parent,\n nestingLevel\n )}\\n`;\n }\n }\n\n // process child blocks\n if (mdBlocks.children && mdBlocks.children.length > 0) {\n if (\n mdBlocks.type === \"synced_block\" ||\n mdBlocks.type === \"column_list\" ||\n mdBlocks.type === \"column\"\n ) {\n let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier);\n // mdOutput[pageIdentifier] += mdstr[pageIdentifier];\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n Object.keys(mdstr).forEach((key) => {\n if (mdOutput[key]) {\n mdOutput[key] + mdstr[key];\n } else {\n mdOutput[key] = mdstr[key];\n }\n });\n mdOutput[pageIdentifier] += mdstr[pageIdentifier];\n\n // mdOutput = { ...mdOutput, ...mdstr };\n } else if (mdBlocks.type === \"child_page\") {\n const childPageTitle = mdBlocks.parent;\n let mdstr = this.toMarkdownString(mdBlocks.children, childPageTitle);\n\n if (this.config.separateChildPage) {\n // console.log(\"<<\", mdOutput, mdstr);\n mdOutput = { ...mdOutput, ...mdstr };\n // console.log(\">>\", mdOutput, \"\\n\\n\");\n } else {\n mdOutput[pageIdentifier] += mdstr[childPageTitle];\n }\n } else if (mdBlocks.type === \"toggle\") {\n // convert children md object to md string\n const toggle_children_md_string = this.toMarkdownString(\n mdBlocks.children\n );\n\n mdOutput[pageIdentifier] += md.toggle(\n mdBlocks.parent,\n toggle_children_md_string[\"parent\"]\n );\n } else {\n let mdstr = this.toMarkdownString(\n mdBlocks.children,\n pageIdentifier,\n nestingLevel + 1\n );\n\n mdOutput[pageIdentifier] += mdstr[\"parent\"];\n }\n }\n });\n\n return mdOutput;\n }\n\n /**\n * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks\n * @param {string} id - notion page id (not database id)\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100 (Default=null)\n * @returns {Promise<MdBlock[]>} - List of markdown blocks\n */\n async pageToMarkdown(\n id: string,\n totalPage: number | null = null\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n this.targetPage = id;\n const blocks = await getBlockChildren(this.notionClient, id, totalPage);\n\n const parsedData = await this.blocksToMarkdown(blocks);\n\n return parsedData;\n }\n\n /**\n * Converts list of Notion Blocks to Markdown Blocks\n * @param {ListBlockChildrenResponseResults | undefined} blocks - List of notion blocks\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100\n * @param {MdBlock[]} mdBlocks - Defines max depth of nesting\n * @returns {Promise<MdBlock[]>} - Array of markdown blocks with their children\n */\n async blocksToMarkdown(\n blocks?: ListBlockChildrenResponseResults,\n totalPage: number | null = null,\n mdBlocks: MdBlock[] = []\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n\n if (!blocks) return mdBlocks;\n\n for (let i = 0; i < blocks.length; i++) {\n let block = blocks[i];\n\n if (\"has_children\" in block && block.has_children) {\n // Get children of this block.\n let child_blocks = await getBlockChildren(\n this.notionClient,\n block.id,\n totalPage\n );\n\n // Push this block to mdBlocks.\n mdBlocks.push({\n type: block.type,\n blockId: block.id,\n parent: await this.blockToMarkdown(block),\n children: [],\n });\n\n // Recursively call blocksToMarkdown to get children of this block.\n let l = mdBlocks.length;\n await this.blocksToMarkdown(\n child_blocks,\n totalPage,\n mdBlocks[l - 1].children\n );\n continue;\n }\n\n let tmp = await this.blockToMarkdown(block);\n mdBlocks.push({\n // @ts-ignore\n type: block.type,\n blockId: block.id,\n parent: tmp,\n children: [],\n });\n }\n return mdBlocks;\n }\n\n /**\n * Converts a Notion Block to a Markdown Block\n * @param {ListBlockChildrenResponseResult} block - single notion block\n * @returns {string} corresponding markdown string of the passed block\n */\n async blockToMarkdown(block: ListBlockChildrenResponseResult) {\n if (typeof block !== \"object\" || !(\"type\" in block)) return \"\";\n\n let parsedData = \"\";\n const { type } = block;\n if (type in this.customTransformers && !!this.customTransformers[type]) {\n const customTransformerValue = await this.customTransformers[type](block);\n if (!!customTransformerValue || customTransformerValue === \"\")\n return customTransformerValue;\n }\n\n switch (type) {\n case \"image\":\n {\n let blockContent = block.image;\n\n const image_caption_plain = blockContent.caption\n .map((item: any) => item.plain_text)\n .join(\"\");\n\n const image_type = blockContent.type;\n\n if (image_type === \"external\")\n return md.image(image_caption_plain, blockContent.external.url);\n\n if (image_type === \"file\")\n return md.image(image_caption_plain, blockContent.file.url);\n }\n break;\n\n case \"divider\": {\n return md.divider();\n }\n\n case \"equation\": {\n return md.equation(block.equation.expression);\n }\n\n case \"video\":\n case \"file\":\n case \"pdf\":\n {\n let blockContent;\n if (type === \"video\") blockContent = block.video;\n if (type === \"file\") blockContent = block.file;\n if (type === \"pdf\") blockContent = block.pdf;\n if (blockContent) {\n const file_type = blockContent.type;\n if (file_type === \"external\")\n return md.link(\"image\", blockContent.external.url);\n if (file_type === \"file\")\n return md.link(\"image\", blockContent.file.url);\n }\n }\n break;\n\n case \"bookmark\":\n case \"embed\":\n case \"link_preview\":\n case \"link_to_page\":\n {\n let blockContent;\n let title: string = type;\n if (type === \"bookmark\") blockContent = block.bookmark;\n if (type === \"embed\") blockContent = block.embed;\n if (type === \"link_preview\") blockContent = block.link_preview;\n if (\n type === \"link_to_page\" &&\n block.link_to_page.type === \"page_id\"\n ) {\n blockContent = { url: block.link_to_page.page_id };\n }\n\n if (blockContent) return md.link(title, blockContent.url);\n }\n break;\n\n case \"child_page\":\n {\n let pageTitle: string = block.child_page.title;\n\n if (this.config.separateChildPage) {\n return pageTitle;\n }\n\n return md.heading2(pageTitle);\n }\n break;\n case \"child_database\":\n {\n let pageTitle = block.child_database.title || `child_database`;\n return pageTitle;\n }\n break;\n\n case \"table\": {\n const { id, has_children } = block;\n let tableArr: string[][] = [];\n if (has_children) {\n const tableRows = await getBlockChildren(this.notionClient, id, 100);\n let rowsPromise = tableRows?.map(async (row) => {\n const { type } = row as any;\n const cells = (row as any)[type][\"cells\"];\n\n /**\n * this is more like a hack since matching the type text was\n * difficult. So converting each cell to paragraph type to\n * reuse the blockToMarkdown function\n */\n let cellStringPromise = cells.map(\n async (cell: any) =>\n await this.blockToMarkdown({\n type: \"paragraph\",\n paragraph: { rich_text: cell },\n } as ListBlockChildrenResponseResult)\n );\n\n const cellStringArr = await Promise.all(cellStringPromise);\n tableArr.push(cellStringArr);\n });\n await Promise.all(rowsPromise || []);\n }\n return md.table(tableArr);\n }\n // Rest of the types\n // \"paragraph\"\n // \"heading_1\"\n // \"heading_2\"\n // \"heading_3\"\n // \"bulleted_list_item\"\n // \"numbered_list_item\"\n // \"quote\"\n // \"to_do\"\n // \"template\"\n // \"synced_block\"\n // \"child_page\"\n // \"child_database\"\n // \"code\"\n // \"callout\"\n // \"breadcrumb\"\n // \"table_of_contents\"\n // \"link_to_page\"\n // \"audio\"\n // \"unsupported\"\n\n default: {\n // In this case typescript is not able to index the types properly, hence ignoring the error\n // @ts-ignore\n let blockContent = block[type].text || block[type].rich_text || [];\n blockContent.map((content: Text | Equation) => {\n if (content.type === \"equation\") {\n parsedData += md.inlineEquation(content.equation.expression);\n return;\n }\n\n const annotations = content.annotations;\n let plain_text = content.plain_text;\n\n plain_text = this.annotatePlainText(plain_text, annotations);\n\n if (content[\"href\"])\n plain_text = md.link(plain_text, content[\"href\"]);\n\n parsedData += plain_text;\n });\n }\n }\n\n switch (type) {\n case \"code\":\n {\n parsedData = md.codeBlock(parsedData, block[type].language);\n }\n break;\n\n case \"heading_1\":\n {\n parsedData = md.heading1(parsedData);\n }\n break;\n\n case \"heading_2\":\n {\n parsedData = md.heading2(parsedData);\n }\n break;\n\n case \"heading_3\":\n {\n parsedData = md.heading3(parsedData);\n }\n break;\n\n case \"quote\":\n {\n parsedData = md.quote(parsedData);\n }\n break;\n\n case \"callout\":\n {\n const { id, has_children } = block;\n let callout_string = \"\";\n\n if (!has_children) {\n return md.callout(parsedData, block[type].icon);\n }\n\n const callout_children_object = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n // // parse children blocks to md object\n const callout_children = await this.blocksToMarkdown(\n callout_children_object\n );\n\n callout_string += `${parsedData}\\n`;\n callout_children.map((child) => {\n callout_string += `${child.parent}\\n\\n`;\n });\n\n parsedData = md.callout(callout_string.trim(), block[type].icon);\n }\n break;\n\n case \"bulleted_list_item\":\n {\n parsedData = md.bullet(parsedData);\n }\n break;\n\n case \"numbered_list_item\":\n {\n parsedData = md.bullet(parsedData, block.numbered_list_item.number);\n }\n break;\n\n case \"to_do\":\n {\n parsedData = md.todo(parsedData, block.to_do.checked);\n }\n break;\n }\n\n return parsedData;\n }\n\n /**\n * Annoate text using provided annotations\n * @param {string} text - String to be annotated\n * @param {Annotations} annotations - Annotation object of a notion block\n * @returns {string} - Annotated text\n */\n annotatePlainText(text: string, annotations: Annotations): string {\n // if text is all spaces, don't annotate\n if (text.match(/^\\s*$/)) return text;\n\n const leadingSpaceMatch = text.match(/^(\\s*)/);\n const trailingSpaceMatch = text.match(/(\\s*)$/);\n\n const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : \"\";\n const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : \"\";\n\n text = text.trim();\n\n if (text !== \"\") {\n if (annotations.code) text = md.inlineCode(text);\n if (annotations.bold) text = md.bold(text);\n if (annotations.italic) text = md.italic(text);\n if (annotations.strikethrough) text = md.strikethrough(text);\n if (annotations.underline) text = md.underline(text);\n }\n\n return leading_space + text + trailing_space;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { Client } from '@notionhq/client';
2
- import { ListBlockChildrenResponse } from '@notionhq/client/build/src/api-endpoints';
1
+ import { Client } from "@notionhq/client";
2
+ import { ListBlockChildrenResponse } from "@notionhq/client/build/src/api-endpoints";
3
3
  export type BlockAttributes = {
4
4
  numbered_list_item?: {
5
5
  number?: number;
@@ -8,9 +8,14 @@ export type BlockAttributes = {
8
8
  export type ListBlockChildrenResponseResults = ListBlockChildrenResponse["results"] & BlockAttributes;
9
9
  export type ListBlockChildrenResponseResult = ListBlockChildrenResponseResults[0] & BlockAttributes;
10
10
  export type TextRequest = string;
11
+ export type ConfigurationOptions = {
12
+ separateChildPage?: boolean;
13
+ };
11
14
  export interface NotionToMarkdownOptions {
12
15
  notionClient: Client;
16
+ config?: ConfigurationOptions;
13
17
  }
18
+ export type MdStringObject = Record<string, string>;
14
19
  export type MdBlock = {
15
20
  type?: string;
16
21
  blockId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EACL,yBAAyB,EAC1B,MAAM,0CAA0C,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,CAAC,EAAE;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AACF,MAAM,MAAM,gCAAgC,GAC1C,yBAAyB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;AAEzD,MAAM,MAAM,+BAA+B,GACzC,gCAAgC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EACH,SAAS,GACT,MAAM,GACN,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,QAAQ,GACR,MAAM,GAC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;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC5D,IAAI,CAAC;AAET,MAAM,MAAM,iBAAiB,GAAG,CAC9B,KAAK,EAAE,+BAA+B,KACnC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["import { Client } from '@notionhq/client';\nimport {\n ListBlockChildrenResponse,\n} from '@notionhq/client/build/src/api-endpoints';\n\nexport type BlockAttributes = {\n numbered_list_item?: {\n number?: number;\n };\n};\nexport type ListBlockChildrenResponseResults =\n ListBlockChildrenResponse[\"results\"] & BlockAttributes;\n\nexport type ListBlockChildrenResponseResult =\n ListBlockChildrenResponseResults[0] & BlockAttributes;\n\nexport type TextRequest = string;\n\nexport interface NotionToMarkdownOptions {\n notionClient: Client;\n}\n\nexport type MdBlock = {\n type?: string;\n blockId: string;\n parent: string;\n children: MdBlock[];\n};\n\nexport type Annotations = {\n bold: boolean;\n italic: boolean;\n strikethrough: boolean;\n underline: boolean;\n code: boolean;\n color:\n | \"default\"\n | \"gray\"\n | \"brown\"\n | \"orange\"\n | \"yellow\"\n | \"green\"\n | \"blue\"\n | \"purple\"\n | \"pink\"\n | \"red\"\n | \"gray_background\"\n | \"brown_background\"\n | \"orange_background\"\n | \"yellow_background\"\n | \"green_background\"\n | \"blue_background\"\n | \"purple_background\"\n | \"pink_background\"\n | \"red_background\";\n};\n\nexport type Text = {\n type: \"text\";\n text: {\n content: string;\n link: {\n url: TextRequest;\n } | null;\n };\n annotations: Annotations;\n plain_text: string;\n href: string | null;\n};\n\nexport type Equation = {\n type: \"equation\";\n equation: { \n expression: string;\n },\n annotations: {\n bold: false;\n italic: false;\n strikethrough: false;\n underline: false;\n code: false;\n color: \"default\";\n },\n plain_text: string;\n href: null;\n};\n\nexport type CalloutIcon =\n | { type: \"emoji\"; emoji?: string }\n | { type: \"external\"; external?: { url: string } }\n | { type: \"file\"; file: { url: string; expiry_time: string } }\n | null;\n\nexport type CustomTransformer = (\n block: ListBlockChildrenResponseResult\n) => string | Promise<string>;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["import { Client } from \"@notionhq/client\";\nimport { ListBlockChildrenResponse } from \"@notionhq/client/build/src/api-endpoints\";\n\nexport type BlockAttributes = {\n numbered_list_item?: {\n number?: number;\n };\n};\nexport type ListBlockChildrenResponseResults =\n ListBlockChildrenResponse[\"results\"] & BlockAttributes;\n\nexport type ListBlockChildrenResponseResult =\n ListBlockChildrenResponseResults[0] & BlockAttributes;\n\nexport type TextRequest = string;\n\nexport type ConfigurationOptions = {\n separateChildPage?: boolean;\n};\nexport interface NotionToMarkdownOptions {\n notionClient: Client;\n config?: ConfigurationOptions;\n}\n\nexport type MdStringObject = Record<string, string>;\n\nexport type MdBlock = {\n type?: string;\n blockId: string;\n parent: string;\n children: MdBlock[];\n};\n\nexport type Annotations = {\n bold: boolean;\n italic: boolean;\n strikethrough: boolean;\n underline: boolean;\n code: boolean;\n color:\n | \"default\"\n | \"gray\"\n | \"brown\"\n | \"orange\"\n | \"yellow\"\n | \"green\"\n | \"blue\"\n | \"purple\"\n | \"pink\"\n | \"red\"\n | \"gray_background\"\n | \"brown_background\"\n | \"orange_background\"\n | \"yellow_background\"\n | \"green_background\"\n | \"blue_background\"\n | \"purple_background\"\n | \"pink_background\"\n | \"red_background\";\n};\n\nexport type Text = {\n type: \"text\";\n text: {\n content: string;\n link: {\n url: TextRequest;\n } | null;\n };\n annotations: Annotations;\n plain_text: string;\n href: string | null;\n};\n\nexport type Equation = {\n type: \"equation\";\n equation: {\n expression: string;\n };\n annotations: {\n bold: false;\n italic: false;\n strikethrough: false;\n underline: false;\n code: false;\n color: \"default\";\n };\n plain_text: string;\n href: null;\n};\n\nexport type CalloutIcon =\n | { type: \"emoji\"; emoji?: string }\n | { type: \"external\"; external?: { url: string } }\n | { type: \"file\"; file: { url: string; expiry_time: string } }\n | null;\n\nexport type CustomTransformer = (\n block: ListBlockChildrenResponseResult\n) => string | Promise<string>;\n"]}
package/build/utils/md.js CHANGED
@@ -90,7 +90,7 @@ const addTabSpace = (text, n = 0) => {
90
90
  const tab = " ";
91
91
  for (let i = 0; i < n; i++) {
92
92
  if (text.includes("\n")) {
93
- const multiLineText = text.split(/(?<=\n)/).join(tab);
93
+ const multiLineText = text.split(/(?:^|\n)/).join(`\n${tab}`);
94
94
  text = tab + multiLineText;
95
95
  }
96
96
  else
@@ -1 +1 @@
1
- {"version":3,"file":"md.js","sourceRoot":"","sources":["../../src/utils/md.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;AAEpC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEK,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7C,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf;AAEK,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE;IACrC,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE;IAC5C,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE;IACxC,OAAO,MAAM,IAAI,MAAM,CAAC;AAC1B,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB;AAEK,MAA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AI,GAAG,GAAG,GAAG,aAAa,CAAC;SAC5B;;YAAM,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;KAC1B;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AATW,QAAA,WAAW,eAStB;AAEK,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AAEK,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,QAAiB,EAAE,EAAE;IAC5D,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,IAAI,EAAE,CAAC;IACpC,OAAO;aACI,OAAO;;EAElB,QAAQ,IAAI,EAAE;;aAEH,CAAC;AACd,CAAC,CAAC;AARW,QAAA,MAAM,UAQjB;AAEK,MAAM,KAAK,GAAG,CAAC,KAAiB,EAAE,EAAE;IACzC,OAAO,IAAA,wBAAa,EAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB","sourcesContent":["import { CalloutIcon } from \"../types\";\nimport markdownTable from \"markdown-table\";\n\nexport const inlineCode = (text: string) => {\n return `\\`${text}\\``;\n};\n\nexport const inlineEquation = (text: string) => {\n return `$${text}$`;\n};\n\nexport const bold = (text: string) => {\n return `**${text}**`;\n};\n\nexport const italic = (text: string) => {\n return `_${text}_`;\n};\n\nexport const strikethrough = (text: string) => {\n return `~~${text}~~`;\n};\n\nexport const underline = (text: string) => {\n return `<u>${text}</u>`;\n};\n\nexport const link = (text: string, href: string) => {\n return `[${text}](${href})`;\n};\n\nexport const codeBlock = (text: string, language?: string) => {\n if (language === \"plain text\") language = \"text\";\n\n return `\\`\\`\\`${language}\n${text}\n\\`\\`\\``;\n};\n\nexport const equation = (text: string) => {\n return `$$\n${text}\n$$`;\n};\n\nexport const heading1 = (text: string) => {\n return `# ${text}`;\n};\n\nexport const heading2 = (text: string) => {\n return `## ${text}`;\n};\n\nexport const heading3 = (text: string) => {\n return `### ${text}`;\n};\n\nexport const quote = (text: string) => {\n // the replace is done to handle multiple lines\n return `> ${text.replace(/\\n/g, \" \\n> \")}`;\n};\n\nexport const callout = (text: string, icon?: CalloutIcon) => {\n let emoji: string | undefined;\n if (icon?.type === \"emoji\") {\n emoji = icon.emoji;\n }\n\n // the replace is done to handle multiple lines\n return `> ${emoji ? emoji + \" \" : \"\"}${text.replace(/\\n/g, \" \\n> \")}`;\n};\n\nexport const bullet = (text: string, count?: number) => {\n let renderText = text.trim();\n return count ? `${count}. ${renderText}` : `- ${renderText}`;\n};\n\nexport const todo = (text: string, checked: boolean) => {\n return checked ? `- [x] ${text}` : `- [ ] ${text}`;\n};\n\nexport const image = (alt: string, href: string) => {\n return `![${alt}](${href})`;\n};\n\nexport const addTabSpace = (text: string, n = 0) => {\n const tab = \"\t\";\n for (let i = 0; i < n; i++) {\n if (text.includes(\"\\n\")) {\n const multiLineText = text.split(/(?<=\\n)/).join(tab);\n text = tab + multiLineText;\n } else text = tab + text;\n }\n return text;\n};\n\nexport const divider = () => {\n return \"---\";\n};\n\nexport const toggle = (summary?: string, children?: string) => {\n if (!summary) return children || \"\";\n return `<details>\n <summary>${summary}</summary>\n\n${children || \"\"}\n\n </details>`;\n};\n\nexport const table = (cells: string[][]) => {\n return markdownTable(cells);\n};\n"]}
1
+ {"version":3,"file":"md.js","sourceRoot":"","sources":["../../src/utils/md.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;AAEpC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEK,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7C,OAAO,IAAI,IAAI,GAAG,CAAC;AACrB,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,OAAO,KAAK,IAAI,IAAI,CAAC;AAC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KAAK,GAAG,KAAK,IAAI,GAAG,CAAC;AAC9B,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAEK,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE;IACjD,MAAM,GAAG,GAAG,GAAG,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACvB,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;YAC9D,IAAI,GAAG,GAAG,GAAG,aAAa,CAAC;SAC5B;;YAAM,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;KAC1B;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AATW,QAAA,WAAW,eAStB;AAEK,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AAEK,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,QAAiB,EAAE,EAAE;IAC5D,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,IAAI,EAAE,CAAC;IACpC,OAAO;aACI,OAAO;;EAElB,QAAQ,IAAI,EAAE;;aAEH,CAAC;AACd,CAAC,CAAC;AARW,QAAA,MAAM,UAQjB;AAEK,MAAM,KAAK,GAAG,CAAC,KAAiB,EAAE,EAAE;IACzC,OAAO,IAAA,wBAAa,EAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB","sourcesContent":["import { CalloutIcon } from \"../types\";\nimport markdownTable from \"markdown-table\";\n\nexport const inlineCode = (text: string) => {\n return `\\`${text}\\``;\n};\n\nexport const inlineEquation = (text: string) => {\n return `$${text}$`;\n};\n\nexport const bold = (text: string) => {\n return `**${text}**`;\n};\n\nexport const italic = (text: string) => {\n return `_${text}_`;\n};\n\nexport const strikethrough = (text: string) => {\n return `~~${text}~~`;\n};\n\nexport const underline = (text: string) => {\n return `<u>${text}</u>`;\n};\n\nexport const link = (text: string, href: string) => {\n return `[${text}](${href})`;\n};\n\nexport const codeBlock = (text: string, language?: string) => {\n if (language === \"plain text\") language = \"text\";\n\n return `\\`\\`\\`${language}\n${text}\n\\`\\`\\``;\n};\n\nexport const equation = (text: string) => {\n return `$$\n${text}\n$$`;\n};\n\nexport const heading1 = (text: string) => {\n return `# ${text}`;\n};\n\nexport const heading2 = (text: string) => {\n return `## ${text}`;\n};\n\nexport const heading3 = (text: string) => {\n return `### ${text}`;\n};\n\nexport const quote = (text: string) => {\n // the replace is done to handle multiple lines\n return `> ${text.replace(/\\n/g, \" \\n> \")}`;\n};\n\nexport const callout = (text: string, icon?: CalloutIcon) => {\n let emoji: string | undefined;\n if (icon?.type === \"emoji\") {\n emoji = icon.emoji;\n }\n\n // the replace is done to handle multiple lines\n return `> ${emoji ? emoji + \" \" : \"\"}${text.replace(/\\n/g, \" \\n> \")}`;\n};\n\nexport const bullet = (text: string, count?: number) => {\n let renderText = text.trim();\n return count ? `${count}. ${renderText}` : `- ${renderText}`;\n};\n\nexport const todo = (text: string, checked: boolean) => {\n return checked ? `- [x] ${text}` : `- [ ] ${text}`;\n};\n\nexport const image = (alt: string, href: string) => {\n return `![${alt}](${href})`;\n};\n\nexport const addTabSpace = (text: string, n = 0) => {\n const tab = \"\t\";\n for (let i = 0; i < n; i++) {\n if (text.includes(\"\\n\")) {\n const multiLineText = text.split(/(?:^|\\n)/).join(`\\n${tab}`);\n text = tab + multiLineText;\n } else text = tab + text;\n }\n return text;\n};\n\nexport const divider = () => {\n return \"---\";\n};\n\nexport const toggle = (summary?: string, children?: string) => {\n if (!summary) return children || \"\";\n return `<details>\n <summary>${summary}</summary>\n\n${children || \"\"}\n\n </details>`;\n};\n\nexport const table = (cells: string[][]) => {\n return markdownTable(cells);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"notion.d.ts","sourceRoot":"","sources":["../../src/utils/notion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,eAAO,MAAM,gBAAgB,iBACb,MAAM,YACV,MAAM,aACL,MAAM,GAAG,IAAI,8CA2BzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAC3B,gCAAgC,SAczC,CAAC"}
1
+ {"version":3,"file":"notion.d.ts","sourceRoot":"","sources":["../../src/utils/notion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,eAAO,MAAM,gBAAgB,iBACb,MAAM,YACV,MAAM,aACL,MAAM,GAAG,IAAI,8CA2BzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAC3B,gCAAgC,SAazC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"notion.js","sourceRoot":"","sources":["../../src/utils/notion.ts"],"names":[],"mappings":";;;AAIO,MAAM,gBAAgB,GAAG,KAAK,EACnC,YAAoB,EACpB,QAAgB,EAChB,SAAwB,EACxB,EAAE;IACF,IAAI;QACF,IAAI,MAAM,GAAqC,EAAE,CAAC;QAClD,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,YAAY,GAAG,SAAS,CAAC;QAE7B,GAAG;YACD,MAAM,QAAQ,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACxD,YAAY,EAAE,YAAY;gBAC1B,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAA8B,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;YAEjC,YAAY,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC;YACrC,SAAS,IAAI,CAAC,CAAC;SAChB,QACC,YAAY,IAAI,IAAI;YACpB,CAAC,SAAS,IAAI,IAAI,IAAI,SAAS,GAAG,SAAS,CAAC,EAC5C;QAEF,IAAA,gCAAwB,EAAC,MAAM,CAAC,CAAC;QACjC,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,OAAO,EAAE,CAAC;KACX;AACH,CAAC,CAAC;AA9BW,QAAA,gBAAgB,oBA8B3B;AAEK,MAAM,wBAAwB,GAAG,CACtC,MAAwC,EACxC,EAAE;IACF,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAE1B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC1D,cAAc;YACd,aAAa;YACb,KAAK,CAAC,kBAAkB,CAAC,MAAM,GAAG,EAAE,iBAAiB,CAAC;SACvD;aACI;YACH,iBAAiB,GAAG,CAAC,CAAC;SACvB;KACF;AACH,CAAC,CAAC;AAfW,QAAA,wBAAwB,4BAenC","sourcesContent":["import { Client } from \"@notionhq/client\";\nimport { ListBlockChildrenResponse } from \"@notionhq/client/build/src/api-endpoints\";\nimport { ListBlockChildrenResponseResults } from \"../types\";\n\nexport const getBlockChildren = async (\n notionClient: Client,\n block_id: string,\n totalPage: number | null\n) => {\n try {\n let result: ListBlockChildrenResponseResults = [];\n let pageCount = 0;\n let start_cursor = undefined;\n\n do {\n const response = (await notionClient.blocks.children.list({\n start_cursor: start_cursor,\n block_id: block_id,\n })) as ListBlockChildrenResponse;\n result.push(...response.results);\n\n start_cursor = response?.next_cursor;\n pageCount += 1;\n } while (\n start_cursor != null &&\n (totalPage == null || pageCount < totalPage)\n );\n\n modifyNumberedListObject(result);\n return result;\n } catch (e) {\n console.log(e);\n return [];\n }\n};\n\nexport const modifyNumberedListObject = (\n blocks: ListBlockChildrenResponseResults\n) => {\n let numberedListIndex = 0;\n\n for (const block of blocks) {\n if (\"type\" in block && block.type === \"numbered_list_item\") {\n // add numbers\n // @ts-ignore\n block.numbered_list_item.number = ++numberedListIndex;\n }\n else {\n numberedListIndex = 0;\n }\n }\n};\n"]}
1
+ {"version":3,"file":"notion.js","sourceRoot":"","sources":["../../src/utils/notion.ts"],"names":[],"mappings":";;;AAIO,MAAM,gBAAgB,GAAG,KAAK,EACnC,YAAoB,EACpB,QAAgB,EAChB,SAAwB,EACxB,EAAE;IACF,IAAI;QACF,IAAI,MAAM,GAAqC,EAAE,CAAC;QAClD,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,YAAY,GAAG,SAAS,CAAC;QAE7B,GAAG;YACD,MAAM,QAAQ,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACxD,YAAY,EAAE,YAAY;gBAC1B,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAA8B,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;YAEjC,YAAY,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC;YACrC,SAAS,IAAI,CAAC,CAAC;SAChB,QACC,YAAY,IAAI,IAAI;YACpB,CAAC,SAAS,IAAI,IAAI,IAAI,SAAS,GAAG,SAAS,CAAC,EAC5C;QAEF,IAAA,gCAAwB,EAAC,MAAM,CAAC,CAAC;QACjC,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,OAAO,EAAE,CAAC;KACX;AACH,CAAC,CAAC;AA9BW,QAAA,gBAAgB,oBA8B3B;AAEK,MAAM,wBAAwB,GAAG,CACtC,MAAwC,EACxC,EAAE;IACF,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAE1B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC1D,cAAc;YACd,aAAa;YACb,KAAK,CAAC,kBAAkB,CAAC,MAAM,GAAG,EAAE,iBAAiB,CAAC;SACvD;aAAM;YACL,iBAAiB,GAAG,CAAC,CAAC;SACvB;KACF;AACH,CAAC,CAAC;AAdW,QAAA,wBAAwB,4BAcnC","sourcesContent":["import { Client } from \"@notionhq/client\";\nimport { ListBlockChildrenResponse } from \"@notionhq/client/build/src/api-endpoints\";\nimport { ListBlockChildrenResponseResults } from \"../types\";\n\nexport const getBlockChildren = async (\n notionClient: Client,\n block_id: string,\n totalPage: number | null\n) => {\n try {\n let result: ListBlockChildrenResponseResults = [];\n let pageCount = 0;\n let start_cursor = undefined;\n\n do {\n const response = (await notionClient.blocks.children.list({\n start_cursor: start_cursor,\n block_id: block_id,\n })) as ListBlockChildrenResponse;\n result.push(...response.results);\n\n start_cursor = response?.next_cursor;\n pageCount += 1;\n } while (\n start_cursor != null &&\n (totalPage == null || pageCount < totalPage)\n );\n\n modifyNumberedListObject(result);\n return result;\n } catch (e) {\n console.log(e);\n return [];\n }\n};\n\nexport const modifyNumberedListObject = (\n blocks: ListBlockChildrenResponseResults\n) => {\n let numberedListIndex = 0;\n\n for (const block of blocks) {\n if (\"type\" in block && block.type === \"numbered_list_item\") {\n // add numbers\n // @ts-ignore\n block.numbered_list_item.number = ++numberedListIndex;\n } else {\n numberedListIndex = 0;\n }\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notion-to-md",
3
- "version": "2.5.6",
3
+ "version": "2.7.0",
4
4
  "engines": {
5
5
  "node": ">=12"
6
6
  },