notion-to-md 2.6.0 → 3.0.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 +17 -40
- package/build/notion-to-md.d.ts +3 -3
- package/build/notion-to-md.d.ts.map +1 -1
- package/build/notion-to-md.js +72 -39
- package/build/notion-to-md.js.map +1 -1
- package/build/types/index.d.ts +3 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js.map +1 -1
- package/build/utils/md.d.ts +1 -1
- package/build/utils/md.d.ts.map +1 -1
- package/build/utils/md.js +21 -2
- package/build/utils/md.js.map +1 -1
- package/build/utils/md.spec.js +7 -3
- package/build/utils/md.spec.js.map +1 -1
- package/build/utils/notion.d.ts.map +1 -1
- package/build/utils/notion.js +15 -21
- package/build/utils/notion.js.map +1 -1
- package/package.json +3 -4
- package/build/utils/misc.d.ts +0 -2
- package/build/utils/misc.d.ts.map +0 -1
- package/build/utils/misc.js +0 -10
- package/build/utils/misc.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
2
3
|
<!--
|
|
3
4
|
💡 For better readability and detailed instructions head over to the [wiki](https://github.com/souvikinator/notion-to-md/wiki).
|
|
4
5
|
-->
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
Notion-to-MD is a Node.js package that allows you to convert Notion pages to Markdown format.
|
|
17
18
|
</p>
|
|
18
19
|
<p align="center">
|
|
19
|
-
Convert notion pages,
|
|
20
|
+
Convert notion pages, blocks and list of blocks to markdown (supports nesting) using <a href="https://github.com/makenotion/notion-sdk-js">notion-sdk-js</a>
|
|
20
21
|
</p>
|
|
21
22
|
<p align="center">
|
|
22
23
|
<img src="https://img.shields.io/github/stars/souvikinator/notion-to-md?style=for-the-badge"
|
|
@@ -35,9 +36,12 @@ npm install notion-to-md
|
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
## Usage
|
|
38
|
-
> **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
|
|
39
|
+
> ⚠️ **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).
|
|
39
40
|
> Details on methods can be found in [API section](https://github.com/souvikinator/notion-to-md#api)
|
|
40
41
|
|
|
42
|
+
> ⚠️ **Note:** Starting from v2.7.0, `toMarkdownString` no longer automatically saves child pages.
|
|
43
|
+
> Now it provides an object containing the markdown content of child pages.
|
|
44
|
+
|
|
41
45
|
## converting markdown objects to markdown string
|
|
42
46
|
|
|
43
47
|
This is how the notion page looks for this example:
|
|
@@ -61,45 +65,23 @@ const n2m = new NotionToMarkdown({ notionClient: notion });
|
|
|
61
65
|
(async () => {
|
|
62
66
|
const mdblocks = await n2m.pageToMarkdown("target_page_id");
|
|
63
67
|
const mdString = n2m.toMarkdownString(mdblocks);
|
|
64
|
-
console.log(mdString);
|
|
68
|
+
console.log(mdString.parent);
|
|
65
69
|
})();
|
|
66
70
|
```
|
|
67
|
-
|
|
68
|
-
**Output:**
|
|
69
|
-
|
|
70
71
|
<img src="https://imgur.com/XrUYrZ0.png" width="500" />
|
|
71
72
|
|
|
72
|
-
##
|
|
73
|
+
## Separate child page content
|
|
73
74
|
|
|
74
75
|
**parent page content:**
|
|
75
76
|
|
|
76
|
-
<img src="https://
|
|
77
|
+
<img src="https://github.com/souvikinator/notion-to-md/assets/64456160/531ef45d-2dc7-47f4-bbb3-12d6fd44d299" width="500" />
|
|
77
78
|
|
|
78
79
|
**child page content:**
|
|
79
80
|
|
|
80
|
-
<img src="https://
|
|
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
|
|
87
|
-
//writing to file
|
|
88
|
-
fs.writeFile("test.md", mdString, (err) => {
|
|
89
|
-
console.log(err);
|
|
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
|
|
81
|
+
<img src="https://github.com/souvikinator/notion-to-md/assets/64456160/7dde090b-7333-46f8-b6df-e6c9a7b62fa9" width="500" />
|
|
99
82
|
|
|
100
83
|
`NotionToMarkdown` takes second argument, `config`
|
|
101
84
|
|
|
102
|
-
|
|
103
85
|
```javascript
|
|
104
86
|
const { Client } = require("@notionhq/client");
|
|
105
87
|
const { NotionToMarkdown } = require("notion-to-md");
|
|
@@ -110,8 +92,7 @@ const fs = require('fs');
|
|
|
110
92
|
const notion = new Client({
|
|
111
93
|
auth: "your integration token",
|
|
112
94
|
config:{
|
|
113
|
-
|
|
114
|
-
saveToDir: "path/to/output/dir", //default: current directory
|
|
95
|
+
separateChildPage:true, // default: false
|
|
115
96
|
}
|
|
116
97
|
});
|
|
117
98
|
|
|
@@ -122,26 +103,22 @@ const n2m = new NotionToMarkdown({ notionClient: notion });
|
|
|
122
103
|
const mdblocks = await n2m.pageToMarkdown("target_page_id");
|
|
123
104
|
const mdString = n2m.toMarkdownString(mdblocks);
|
|
124
105
|
|
|
125
|
-
|
|
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
|
-
});
|
|
106
|
+
console.log(mdString);
|
|
131
107
|
})();
|
|
132
108
|
```
|
|
133
109
|
|
|
134
110
|
**Output:**
|
|
135
111
|
|
|
136
|
-
|
|
137
|
-
> for the link from parent to child page to work.
|
|
112
|
+
`toMarkdownString` returns an object with target page content corresponding to `parent` property and if any child page exists then it's included in the same object.
|
|
138
113
|
|
|
139
|
-
<img src="https://
|
|
140
|
-
|
|
114
|
+
<img src="https://github.com/souvikinator/notion-to-md/assets/64456160/99bcc14e-46e6-4bed-912d-8b9300c214c1" width="500" />
|
|
115
|
+
|
|
116
|
+
User gets to save the content separately.
|
|
141
117
|
|
|
142
118
|
## converting page to markdown object
|
|
143
119
|
|
|
144
120
|
**Example notion page:**
|
|
121
|
+
|
|
145
122
|
<img src="https://imgur.com/9iqRpBl.png" width="500" />
|
|
146
123
|
|
|
147
124
|
```js
|
package/build/notion-to-md.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
*/
|
|
@@ -13,9 +13,9 @@ export declare class NotionToMarkdown {
|
|
|
13
13
|
* Converts Markdown Blocks to string
|
|
14
14
|
* @param {MdBlock[]} mdBlocks - Array of markdown blocks
|
|
15
15
|
* @param {number} nestingLevel - Defines max depth of nesting
|
|
16
|
-
* @returns {
|
|
16
|
+
* @returns {MdStringObject} - Returns markdown string with child pages separated
|
|
17
17
|
*/
|
|
18
|
-
toMarkdownString(mdBlocks?: MdBlock[],
|
|
18
|
+
toMarkdownString(mdBlocks?: MdBlock[], pageIdentifier?: string, nestingLevel?: number): MdStringObject;
|
|
19
19
|
/**
|
|
20
20
|
* Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
|
|
21
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":"
|
|
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,EAIvB,cAAc,EACf,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,kBAAkB,CAAoC;gBAElD,OAAO,EAAE,uBAAuB;IAW5C,oBAAoB,CAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,GAC7B,gBAAgB;IAMnB;;;;;OAKG;IACH,gBAAgB,CACd,QAAQ,GAAE,OAAO,EAAO,EACxB,cAAc,GAAE,MAAiB,EACjC,YAAY,GAAE,MAAU,GACvB,cAAc;IAyFjB;;;;;OAKG;IACG,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,MAAM,GAAG,IAAW,GAC9B,OAAO,CAAC,OAAO,EAAE,CAAC;IAcrB;;;;;;OAMG;IACG,gBAAgB,CACpB,MAAM,CAAC,EAAE,gCAAgC,EACzC,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,QAAQ,GAAE,OAAO,EAAO,GACvB,OAAO,CAAC,OAAO,EAAE,CAAC;IAyDrB;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,+BAA+B;IA6R5D;;;;;OAKG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM;CAsBlE"}
|
package/build/notion-to-md.js
CHANGED
|
@@ -24,11 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.NotionToMarkdown = void 0;
|
|
27
|
-
const fs_extra_1 = require("fs-extra");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
27
|
const md = __importStar(require("./utils/md"));
|
|
30
28
|
const notion_1 = require("./utils/notion");
|
|
31
|
-
const misc_1 = require("./utils/misc");
|
|
32
29
|
/**
|
|
33
30
|
* Converts a Notion page to Markdown.
|
|
34
31
|
*/
|
|
@@ -36,8 +33,8 @@ class NotionToMarkdown {
|
|
|
36
33
|
constructor(options) {
|
|
37
34
|
this.notionClient = options.notionClient;
|
|
38
35
|
const defaultConfig = {
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
separateChildPage: false,
|
|
37
|
+
convertImagesToBase64: false,
|
|
41
38
|
};
|
|
42
39
|
this.targetPage = "";
|
|
43
40
|
this.config = { ...defaultConfig, ...options.config };
|
|
@@ -51,24 +48,31 @@ class NotionToMarkdown {
|
|
|
51
48
|
* Converts Markdown Blocks to string
|
|
52
49
|
* @param {MdBlock[]} mdBlocks - Array of markdown blocks
|
|
53
50
|
* @param {number} nestingLevel - Defines max depth of nesting
|
|
54
|
-
* @returns {
|
|
51
|
+
* @returns {MdStringObject} - Returns markdown string with child pages separated
|
|
55
52
|
*/
|
|
56
|
-
toMarkdownString(mdBlocks = [],
|
|
57
|
-
let
|
|
53
|
+
toMarkdownString(mdBlocks = [], pageIdentifier = "parent", nestingLevel = 0) {
|
|
54
|
+
let mdOutput = {};
|
|
58
55
|
mdBlocks.forEach((mdBlocks) => {
|
|
59
56
|
// NOTE: toggle in the child blocks logic
|
|
60
57
|
// adding a toggle check prevents duplicate
|
|
61
58
|
// rendering of toggle title
|
|
62
59
|
// process parent blocks
|
|
63
|
-
if (mdBlocks.parent &&
|
|
60
|
+
if (mdBlocks.parent &&
|
|
61
|
+
mdBlocks.type !== "toggle" &&
|
|
62
|
+
mdBlocks.type !== "child_page") {
|
|
64
63
|
if (mdBlocks.type !== "to_do" &&
|
|
65
64
|
mdBlocks.type !== "bulleted_list_item" &&
|
|
66
65
|
mdBlocks.type !== "numbered_list_item") {
|
|
66
|
+
// initialize if key doesn't exist
|
|
67
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
68
|
+
mdOutput;
|
|
67
69
|
// add extra line breaks non list blocks
|
|
68
|
-
|
|
70
|
+
mdOutput[pageIdentifier] += `\n${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n\n`;
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
71
|
-
|
|
73
|
+
// initialize if key doesn't exist
|
|
74
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
75
|
+
mdOutput[pageIdentifier] += `${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n`;
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
// process child blocks
|
|
@@ -76,36 +80,39 @@ class NotionToMarkdown {
|
|
|
76
80
|
if (mdBlocks.type === "synced_block" ||
|
|
77
81
|
mdBlocks.type === "column_list" ||
|
|
78
82
|
mdBlocks.type === "column") {
|
|
79
|
-
let mdstr = this.toMarkdownString(mdBlocks.children);
|
|
80
|
-
|
|
83
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier);
|
|
84
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
85
|
+
Object.keys(mdstr).forEach((key) => {
|
|
86
|
+
if (mdOutput[key]) {
|
|
87
|
+
mdOutput[key] += mdstr[key];
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
mdOutput[key] = mdstr[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
81
93
|
}
|
|
82
94
|
else if (mdBlocks.type === "child_page") {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const filePath = path.join(this.config.saveToDir, `${fileName}.md`);
|
|
88
|
-
// save to file
|
|
89
|
-
(0, fs_extra_1.ensureFile)(filePath).then(() => {
|
|
90
|
-
(0, fs_extra_1.writeFile)(filePath, mdstr);
|
|
91
|
-
});
|
|
95
|
+
const childPageTitle = mdBlocks.parent;
|
|
96
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, childPageTitle);
|
|
97
|
+
if (this.config.separateChildPage) {
|
|
98
|
+
mdOutput = { ...mdOutput, ...mdstr };
|
|
92
99
|
}
|
|
93
100
|
else {
|
|
94
|
-
|
|
101
|
+
mdOutput[pageIdentifier] += mdstr[childPageTitle];
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
else if (mdBlocks.type === "toggle") {
|
|
98
105
|
// convert children md object to md string
|
|
99
106
|
const toggle_children_md_string = this.toMarkdownString(mdBlocks.children);
|
|
100
|
-
|
|
107
|
+
mdOutput[pageIdentifier] += md.toggle(mdBlocks.parent, toggle_children_md_string["parent"]);
|
|
101
108
|
}
|
|
102
109
|
else {
|
|
103
|
-
let mdstr = this.toMarkdownString(mdBlocks.children,
|
|
104
|
-
|
|
110
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier, nestingLevel + 1);
|
|
111
|
+
mdOutput[pageIdentifier] += mdstr["parent"];
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
});
|
|
108
|
-
return
|
|
115
|
+
return mdOutput;
|
|
109
116
|
}
|
|
110
117
|
/**
|
|
111
118
|
* Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
|
|
@@ -148,8 +155,12 @@ class NotionToMarkdown {
|
|
|
148
155
|
children: [],
|
|
149
156
|
});
|
|
150
157
|
// Recursively call blocksToMarkdown to get children of this block.
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
// check for custom transformer before parsing child
|
|
159
|
+
if (!(block.type in this.customTransformers) &&
|
|
160
|
+
!this.customTransformers[block.type]) {
|
|
161
|
+
let l = mdBlocks.length;
|
|
162
|
+
await this.blocksToMarkdown(child_blocks, totalPage, mdBlocks[l - 1].children);
|
|
163
|
+
}
|
|
153
164
|
continue;
|
|
154
165
|
}
|
|
155
166
|
let tmp = await this.blockToMarkdown(block);
|
|
@@ -182,14 +193,27 @@ class NotionToMarkdown {
|
|
|
182
193
|
case "image":
|
|
183
194
|
{
|
|
184
195
|
let blockContent = block.image;
|
|
196
|
+
let image_title = "image";
|
|
185
197
|
const image_caption_plain = blockContent.caption
|
|
186
198
|
.map((item) => item.plain_text)
|
|
187
199
|
.join("");
|
|
188
200
|
const image_type = blockContent.type;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
let link = "";
|
|
202
|
+
if (image_type === "external") {
|
|
203
|
+
link = blockContent.external.url;
|
|
204
|
+
}
|
|
205
|
+
if (image_type === "file") {
|
|
206
|
+
link = blockContent.file.url;
|
|
207
|
+
}
|
|
208
|
+
// image caption with high priority
|
|
209
|
+
if (image_caption_plain.trim().length > 0) {
|
|
210
|
+
image_title = image_caption_plain;
|
|
211
|
+
}
|
|
212
|
+
else if (image_type === "file" || image_type === "external") {
|
|
213
|
+
const matches = link.match(/[^\/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))/);
|
|
214
|
+
image_title = matches ? matches[0] : image_title;
|
|
215
|
+
}
|
|
216
|
+
return await md.image(image_title, link, this.config.convertImagesToBase64);
|
|
193
217
|
}
|
|
194
218
|
break;
|
|
195
219
|
case "divider": {
|
|
@@ -203,18 +227,29 @@ class NotionToMarkdown {
|
|
|
203
227
|
case "pdf":
|
|
204
228
|
{
|
|
205
229
|
let blockContent;
|
|
230
|
+
let title = type;
|
|
206
231
|
if (type === "video")
|
|
207
232
|
blockContent = block.video;
|
|
208
233
|
if (type === "file")
|
|
209
234
|
blockContent = block.file;
|
|
210
235
|
if (type === "pdf")
|
|
211
236
|
blockContent = block.pdf;
|
|
237
|
+
const caption = blockContent === null || blockContent === void 0 ? void 0 : blockContent.caption.map((item) => item.plain_text).join("");
|
|
212
238
|
if (blockContent) {
|
|
213
239
|
const file_type = blockContent.type;
|
|
240
|
+
let link = "";
|
|
214
241
|
if (file_type === "external")
|
|
215
|
-
|
|
242
|
+
link = blockContent.external.url;
|
|
216
243
|
if (file_type === "file")
|
|
217
|
-
|
|
244
|
+
link = blockContent.file.url;
|
|
245
|
+
if (caption && caption.trim().length > 0) {
|
|
246
|
+
title = caption;
|
|
247
|
+
}
|
|
248
|
+
else if (link) {
|
|
249
|
+
const matches = link.match(/[^\/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))/);
|
|
250
|
+
title = matches ? matches[0] : type;
|
|
251
|
+
}
|
|
252
|
+
return md.link(title, link);
|
|
218
253
|
}
|
|
219
254
|
}
|
|
220
255
|
break;
|
|
@@ -242,10 +277,8 @@ class NotionToMarkdown {
|
|
|
242
277
|
case "child_page":
|
|
243
278
|
{
|
|
244
279
|
let pageTitle = block.child_page.title;
|
|
245
|
-
if (this.config.
|
|
246
|
-
|
|
247
|
-
const filePath = `${fileName}.md`;
|
|
248
|
-
return md.link(pageTitle, filePath);
|
|
280
|
+
if (this.config.separateChildPage) {
|
|
281
|
+
return pageTitle;
|
|
249
282
|
}
|
|
250
283
|
return md.heading2(pageTitle);
|
|
251
284
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notion-to-md.js","sourceRoot":"","sources":["../src/notion-to-md.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAAiD;AACjD,2CAA6B;AAa7B,+CAAiC;AACjC,2CAAkD;AAClD,uCAAsD;AAEtD;;GAEG;AACH,MAAa,gBAAgB;IAM3B,YAAY,OAAgC;QAC1C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,MAAM,aAAa,GAAyB;YAC1C,aAAa,EAAE,KAAK;YACpB,SAAS,EAAE,GAAG;SACf,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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AAiB,CAAC,IAAY,EAAE,WAAwB;QACtD,wCAAwC;QACxC,IAAI,IAAI,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;AAxdD,4CAwdC","sourcesContent":["import { Client } from \"@notionhq/client\";\nimport { ensureFile, writeFile } from \"fs-extra\";\nimport * as path from \"path\";\n\nimport {\n Annotations,\n CustomTransformer,\n ListBlockChildrenResponseResult,\n ListBlockChildrenResponseResults,\n MdBlock,\n NotionToMarkdownOptions,\n Equation,\n Text,\n ConfigurationOptions,\n} from \"./types\";\nimport * as md from \"./utils/md\";\nimport { getBlockChildren } from \"./utils/notion\";\nimport { extractTitleFromMdLink } from \"./utils/misc\";\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 saveChildPage: false,\n saveToDir: \".\",\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 {string} - Returns markdown string\n */\n toMarkdownString(\n mdBlocks: MdBlock[] = [],\n pageName?: string,\n nestingLevel: number = 0\n ): string {\n let mdString = \"\";\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 (mdBlocks.parent && mdBlocks.type !== \"toggle\") {\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 === \"column_list\" ||\n mdBlocks.type === \"column\"\n ) {\n let mdstr = this.toMarkdownString(mdBlocks.children);\n mdString += mdstr;\n } else if (mdBlocks.type === \"child_page\") {\n let mdstr = this.toMarkdownString(mdBlocks.children);\n\n if (this.config.saveChildPage && this.config.saveToDir) {\n const childPageTitle = extractTitleFromMdLink(mdBlocks.parent);\n\n const fileName = childPageTitle.split(\" \").join(\"-\");\n const filePath = path.join(this.config.saveToDir, `${fileName}.md`);\n\n // save to file\n ensureFile(filePath).then(() => {\n writeFile(filePath, mdstr);\n });\n } else {\n mdString += mdstr;\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 mdString += md.toggle(mdBlocks.parent, toggle_children_md_string);\n } else {\n let mdstr = this.toMarkdownString(\n mdBlocks.children,\n pageName,\n nestingLevel + 1\n );\n mdString += mdstr;\n }\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 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.saveChildPage) {\n const fileName = pageTitle.split(\" \").join(\"-\");\n const filePath = `${fileName}.md`;\n return md.link(pageTitle, filePath);\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
|
+
{"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;YACxB,qBAAqB,EAAE,KAAK;SAC7B,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,gBA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GAAG,IAAI,GAAG,cAAc,CAAC;IAC/C,CAAC;CACF;AAthBD,4CAshBC","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 convertImagesToBase64: 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 mdOutput;\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] = 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 } 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 mdOutput = { ...mdOutput, ...mdstr };\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: ListBlockChildrenResponseResult = 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 // check for custom transformer before parsing child\n if (\n !(block.type in this.customTransformers) &&\n !this.customTransformers[block.type]\n ) {\n let l = mdBlocks.length;\n await this.blocksToMarkdown(\n child_blocks,\n totalPage,\n mdBlocks[l - 1].children\n );\n }\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 let image_title = \"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 let link = \"\";\n\n if (image_type === \"external\") {\n link = blockContent.external.url;\n }\n\n if (image_type === \"file\") {\n link = blockContent.file.url;\n }\n\n // image caption with high priority\n if (image_caption_plain.trim().length > 0) {\n image_title = image_caption_plain;\n } else if (image_type === \"file\" || image_type === \"external\") {\n const matches = link.match(/[^\\/\\\\&\\?]+\\.\\w{3,4}(?=([\\?&].*$|$))/);\n image_title = matches ? matches[0] : image_title;\n }\n\n return await md.image(\n image_title,\n link,\n this.config.convertImagesToBase64\n );\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 let title: string = type;\n\n if (type === \"video\") blockContent = block.video;\n if (type === \"file\") blockContent = block.file;\n if (type === \"pdf\") blockContent = block.pdf;\n\n const caption = blockContent?.caption\n .map((item: any) => item.plain_text)\n .join(\"\");\n\n if (blockContent) {\n const file_type = blockContent.type;\n let link = \"\";\n if (file_type === \"external\") link = blockContent.external.url;\n if (file_type === \"file\") link = blockContent.file.url;\n\n if (caption && caption.trim().length > 0) {\n title = caption;\n } else if (link) {\n const matches = link.match(\n /[^\\/\\\\&\\?]+\\.\\w{3,4}(?=([\\?&].*$|$))/\n );\n title = matches ? matches[0] : type;\n }\n\n return md.link(title, link);\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"]}
|
package/build/types/index.d.ts
CHANGED
|
@@ -9,13 +9,14 @@ export type ListBlockChildrenResponseResults = ListBlockChildrenResponse["result
|
|
|
9
9
|
export type ListBlockChildrenResponseResult = ListBlockChildrenResponseResults[0] & BlockAttributes;
|
|
10
10
|
export type TextRequest = string;
|
|
11
11
|
export type ConfigurationOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
separateChildPage?: boolean;
|
|
13
|
+
convertImagesToBase64?: boolean;
|
|
14
14
|
};
|
|
15
15
|
export interface NotionToMarkdownOptions {
|
|
16
16
|
notionClient: Client;
|
|
17
17
|
config?: ConfigurationOptions;
|
|
18
18
|
}
|
|
19
|
+
export type MdStringObject = Record<string, string>;
|
|
19
20
|
export type MdBlock = {
|
|
20
21
|
type?: string;
|
|
21
22
|
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,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAErF,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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E;QAAE,GAAG,EAAE,MAAM,CAAC;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"}
|
package/build/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 convertImagesToBase64?: 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.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const quote: (text: string) => string;
|
|
|
15
15
|
export declare const callout: (text: string, icon?: CalloutIcon) => string;
|
|
16
16
|
export declare const bullet: (text: string, count?: number) => string;
|
|
17
17
|
export declare const todo: (text: string, checked: boolean) => string;
|
|
18
|
-
export declare const image: (alt: string, href: string) => string
|
|
18
|
+
export declare const image: (alt: string, href: string, convertToBase64?: boolean) => Promise<string>;
|
|
19
19
|
export declare const addTabSpace: (text: string, n?: number) => string;
|
|
20
20
|
export declare const divider: () => string;
|
|
21
21
|
export declare const toggle: (summary?: string, children?: string) => string;
|
package/build/utils/md.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"md.d.ts","sourceRoot":"","sources":["../../src/utils/md.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version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MAAM,EAAE,EAAE,WAEtC,CAAC"}
|
package/build/utils/md.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.table = exports.toggle = exports.divider = exports.addTabSpace = exports.image = exports.todo = exports.bullet = exports.callout = exports.quote = exports.heading3 = exports.heading2 = exports.heading1 = exports.equation = exports.codeBlock = exports.link = exports.underline = exports.strikethrough = exports.italic = exports.bold = exports.inlineEquation = exports.inlineCode = void 0;
|
|
7
7
|
const markdown_table_1 = __importDefault(require("markdown-table"));
|
|
8
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
9
|
const inlineCode = (text) => {
|
|
9
10
|
return `\`${text}\``;
|
|
10
11
|
};
|
|
@@ -82,8 +83,26 @@ const todo = (text, checked) => {
|
|
|
82
83
|
return checked ? `- [x] ${text}` : `- [ ] ${text}`;
|
|
83
84
|
};
|
|
84
85
|
exports.todo = todo;
|
|
85
|
-
const image = (alt, href) => {
|
|
86
|
-
|
|
86
|
+
const image = async (alt, href, convertToBase64 = false) => {
|
|
87
|
+
// In case the user does not want to convert the images to Base64
|
|
88
|
+
// or the image is already base64
|
|
89
|
+
if (!convertToBase64 || href.startsWith("data:")) {
|
|
90
|
+
if (href.startsWith("data:")) {
|
|
91
|
+
// Extract base64 data, i.e. the string after 'data:mime/type;base64,'
|
|
92
|
+
const base64 = href.split(",").pop();
|
|
93
|
+
// This overrides incorrect data: string format to png
|
|
94
|
+
// so that browsers can correctly render the data
|
|
95
|
+
return ``;
|
|
96
|
+
}
|
|
97
|
+
return ``;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Otherwise, download the image and convert it to base64
|
|
101
|
+
const res = await (0, node_fetch_1.default)(href);
|
|
102
|
+
const buf = await res.arrayBuffer();
|
|
103
|
+
const base64 = Buffer.from(buf).toString("base64");
|
|
104
|
+
return ``;
|
|
105
|
+
}
|
|
87
106
|
};
|
|
88
107
|
exports.image = image;
|
|
89
108
|
const addTabSpace = (text, n = 0) => {
|
package/build/utils/md.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"md.js","sourceRoot":"","sources":["../../src/utils/md.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;
|
|
1
|
+
{"version":3,"file":"md.js","sourceRoot":"","sources":["../../src/utils/md.ts"],"names":[],"mappings":";;;;;;AACA,oEAA2C;AAE3C,4DAA+B;AAExB,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,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;IACjD,OAAO,IAAI,IAAI,KAAK,IAAI,GAAG,CAAC;AAC9B,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf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\nimport fetch from \"node-fetch\";\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 = async (\n alt: string,\n href: string,\n convertToBase64: boolean = false\n): Promise<string> => {\n // In case the user does not want to convert the images to Base64\n // or the image is already base64\n if (!convertToBase64 || href.startsWith(\"data:\")) {\n if (href.startsWith(\"data:\")) {\n // Extract base64 data, i.e. the string after 'data:mime/type;base64,'\n const base64 = href.split(\",\").pop();\n\n // This overrides incorrect data: string format to png\n // so that browsers can correctly render the data\n return ``;\n }\n\n return ``;\n } else {\n // Otherwise, download the image and convert it to base64\n const res = await fetch(href);\n const buf = await res.arrayBuffer();\n\n const base64 = Buffer.from(buf).toString(\"base64\");\n\n return ``;\n }\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"]}
|
package/build/utils/md.spec.js
CHANGED
|
@@ -82,12 +82,16 @@ describe("List Elements", () => {
|
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
84
|
describe("Image", () => {
|
|
85
|
-
test("Image with alt text", () => {
|
|
86
|
-
expect((0, md_1.image)("simple text", "https://example.com/image")).toBe(``);
|
|
85
|
+
test("Image with alt text", async () => {
|
|
86
|
+
expect(await (0, md_1.image)("simple text", "https://example.com/image", false)).toBe(``);
|
|
87
|
+
});
|
|
88
|
+
test("Image to Base64", async () => {
|
|
89
|
+
const image_markdown = await (0, md_1.image)("simple text", "https://w.wallhaven.cc/full/ex/wallhaven-ex9gwo.png", true);
|
|
90
|
+
expect(image_markdown).toMatch(`;
|
|
87
91
|
});
|
|
88
92
|
});
|
|
89
93
|
describe("Toggle", () => {
|
|
90
|
-
const noSpaces = (text) => text.replace(/\s+/g,
|
|
94
|
+
const noSpaces = (text) => text.replace(/\s+/g, "");
|
|
91
95
|
test("displays content if toggle title is empty", () => {
|
|
92
96
|
expect(noSpaces((0, md_1.toggle)(undefined, "content"))).toBe("content");
|
|
93
97
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"md.spec.js","source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KAAK,IAAI,EAAE;QACjC,MAAM,cAAc,GAAG,MAAM,IAAA,UAAK,EAChC,aAAa,EACb,qDAAqD,EACrD,IAAI,CACL,CAAC;QAEF,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAC5B,0GAA0G,CAC3G,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,QAAQ,CAAC,IAAA,WAAM,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC9D,MAAM,CAAC,QAAQ,CAAC,IAAA,WAAM,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,QAAQ,CAAC,IAAA,WAAM,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAC/C,oDAAoD,CACrD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n callout,\n table,\n inlineCode,\n bold,\n italic,\n strikethrough,\n underline,\n link,\n codeBlock,\n heading1,\n heading2,\n heading3,\n quote,\n bullet,\n todo,\n toggle,\n image,\n inlineEquation,\n equation,\n} from \"./md\";\n\ndescribe(\"Callout\", () => {\n test(\"parses callout without emoji\", () => {\n const text = \"Call out text content.\";\n\n expect(callout(text)).toBe(`> ${text}`);\n });\n\n test(\"parses callout with emoji\", () => {\n const text = \"Call out text content.\";\n\n expect(\n callout(text, {\n type: \"emoji\",\n emoji: \"😍\",\n })\n ).toBe(`> 😍 ${text}`);\n });\n});\n\ndescribe(\"Markdown Table\", () => {\n test(\"parse simple table to markdown table\", () => {\n const mockTable = [\n [\"number\", \"char\"],\n [\"1\", \"a\"],\n [\"2\", \"b\"],\n ];\n\n expect(table(mockTable)).toBe(\n `\n| number | char |\n| ------ | ---- |\n| 1 | a |\n| 2 | b |\n `.trim()\n );\n });\n});\n\ndescribe(\"Text Annotations\", () => {\n test(\"Inline Code\", () => {\n expect(inlineCode(\"simple text\")).toBe(\"`simple text`\");\n });\n test(\"Code Block\", () => {\n expect(codeBlock(\"simple text\", \"javascript\")).toBe(\n `\\`\\`\\`javascript\nsimple text\n\\`\\`\\``.trim()\n );\n });\n test(\"Inline Equation\", () => {\n expect(inlineEquation(\"E = mc^2\")).toBe(\"$E = mc^2$\");\n });\n test(\"Equation Block\", () => {\n expect(equation(\"E = mc^2\")).toBe(\n `$$\nE = mc^2\n$$`.trim()\n );\n });\n test(\"Bold\", () => {\n expect(bold(\"simple text\")).toBe(\"**simple text**\");\n });\n test(\"Italic\", () => {\n expect(italic(\"simple text\")).toBe(\"_simple text_\");\n });\n test(\"StrikeThrough\", () => {\n expect(strikethrough(\"simple text\")).toBe(\"~~simple text~~\");\n });\n test(\"Underline\", () => {\n expect(underline(\"simple text\")).toBe(\"<u>simple text</u>\");\n });\n});\n\ndescribe(\"Headings\", () => {\n test(\"Heading 1\", () => {\n expect(heading1(\"simple text\")).toBe(\"# simple text\");\n });\n test(\"Heading 2\", () => {\n expect(heading2(\"simple text\")).toBe(\"## simple text\");\n });\n test(\"Heading 3\", () => {\n expect(heading3(\"simple text\")).toBe(\"### simple text\");\n });\n});\n\ndescribe(\"List Elements\", () => {\n test(\"Bullet\", () => {\n expect(bullet(\"simple text\")).toBe(\"- simple text\");\n });\n\n test(\"Checked todo\", () => {\n expect(todo(\"simple text\", true)).toBe(\"- [x] simple text\");\n });\n\n test(\"Unchecked todo\", () => {\n expect(todo(\"simple text\", false)).toBe(\"- [ ] simple text\");\n });\n});\n\ndescribe(\"Image\", () => {\n test(\"Image with alt text\", async () => {\n expect(await image(\"simple text\", \"https://example.com/image\", false)).toBe(\n ``\n );\n });\n\n test(\"Image to Base64\", async () => {\n const image_markdown = await image(\n \"simple text\",\n \"https://w.wallhaven.cc/full/ex/wallhaven-ex9gwo.png\",\n true\n );\n\n expect(image_markdown).toMatch(\n `;\n });\n});\n\ndescribe(\"Toggle\", () => {\n const noSpaces = (text: string) => text.replace(/\\s+/g, \"\");\n test(\"displays content if toggle title is empty\", () => {\n expect(noSpaces(toggle(undefined, \"content\"))).toBe(\"content\");\n });\n test(\"return empty string if title and content are empty\", () => {\n expect(noSpaces(toggle(undefined, undefined))).toBe(\"\");\n });\n test(\"Displays toggle with <details> and <summary>\", () => {\n expect(noSpaces(toggle(\"title\", \"content\"))).toBe(\n \"<details><summary>title</summary>content</details>\"\n );\n });\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,
|
|
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,8CAsBzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAC3B,gCAAgC,SAazC,CAAC"}
|
package/build/utils/notion.js
CHANGED
|
@@ -2,27 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.modifyNumberedListObject = exports.getBlockChildren = void 0;
|
|
4
4
|
const getBlockChildren = async (notionClient, block_id, totalPage) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.log(e);
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
5
|
+
let result = [];
|
|
6
|
+
let pageCount = 0;
|
|
7
|
+
let start_cursor = undefined;
|
|
8
|
+
do {
|
|
9
|
+
const response = (await notionClient.blocks.children.list({
|
|
10
|
+
start_cursor: start_cursor,
|
|
11
|
+
block_id: block_id,
|
|
12
|
+
}));
|
|
13
|
+
result.push(...response.results);
|
|
14
|
+
start_cursor = response === null || response === void 0 ? void 0 : response.next_cursor;
|
|
15
|
+
pageCount += 1;
|
|
16
|
+
} while (start_cursor != null &&
|
|
17
|
+
(totalPage == null || pageCount < totalPage));
|
|
18
|
+
(0, exports.modifyNumberedListObject)(result);
|
|
19
|
+
return result;
|
|
26
20
|
};
|
|
27
21
|
exports.getBlockChildren = getBlockChildren;
|
|
28
22
|
const modifyNumberedListObject = (blocks) => {
|
|
@@ -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
|
|
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,MAAM,GAAqC,EAAE,CAAC;IAClD,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,YAAY,GAAG,SAAS,CAAC;IAE7B,GAAG;QACD,MAAM,QAAQ,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;YACxD,YAAY,EAAE,YAAY;YAC1B,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAA8B,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEjC,YAAY,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC;QACrC,SAAS,IAAI,CAAC,CAAC;KAChB,QACC,YAAY,IAAI,IAAI;QACpB,CAAC,SAAS,IAAI,IAAI,IAAI,SAAS,GAAG,SAAS,CAAC,EAC5C;IAEF,IAAA,gCAAwB,EAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAzBW,QAAA,gBAAgB,oBAyB3B;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 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};\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": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=12"
|
|
6
6
|
},
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"description": "convert notion pages, block and list of blocks to markdown (supports nesting)",
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@notionhq/client": "^1.0.1",
|
|
42
|
-
"@types/fs-extra": "^11.0.1",
|
|
43
42
|
"@types/jest": "^27.4.1",
|
|
44
43
|
"@types/markdown-table": "^2.0.0",
|
|
45
44
|
"jest": "^27.4.7",
|
|
@@ -47,7 +46,7 @@
|
|
|
47
46
|
"typescript": "^4.5.4"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
49
|
+
"markdown-table": "^2.0.0",
|
|
50
|
+
"node-fetch": "2"
|
|
52
51
|
}
|
|
53
52
|
}
|
package/build/utils/misc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,WAAY,MAAM,WAIpD,CAAC"}
|
package/build/utils/misc.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractTitleFromMdLink = void 0;
|
|
4
|
-
const extractTitleFromMdLink = (mdLink) => {
|
|
5
|
-
const regex = /\[(.*?)\]/;
|
|
6
|
-
const match = regex.exec(mdLink);
|
|
7
|
-
return match ? match[1] : "";
|
|
8
|
-
};
|
|
9
|
-
exports.extractTitleFromMdLink = extractTitleFromMdLink;
|
|
10
|
-
//# sourceMappingURL=misc.js.map
|
package/build/utils/misc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;AAAO,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAE,EAAE;IACvD,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/B,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC","sourcesContent":["export const extractTitleFromMdLink = (mdLink: string) => {\n const regex = /\\[(.*?)\\]/;\n const match = regex.exec(mdLink);\n return match ? match[1] : \"\";\n};\n"]}
|