notion-to-md 2.3.4 → 2.5.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.
@@ -1,329 +1,367 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.NotionToMarkdown = void 0;
27
- const md = __importStar(require("./utils/md"));
28
- const notion_1 = require("./utils/notion");
29
- /**
30
- * Converts a Notion page to Markdown.
31
- */
32
- class NotionToMarkdown {
33
- constructor(options) {
34
- this.notionClient = options.notionClient;
35
- }
36
- /**
37
- * Converts Markdown Blocks to string
38
- * @param {MdBlock[]} mdBlocks - Array of markdown blocks
39
- * @param {number} nestingLevel - Defines max depth of nesting
40
- * @returns {string} - Returns markdown string
41
- */
42
- toMarkdownString(mdBlocks = [], nestingLevel = 0) {
43
- let mdString = "";
44
- mdBlocks.forEach((mdBlocks) => {
45
- if (mdBlocks.parent) {
46
- mdString += `
47
- ${md.addTabSpace(mdBlocks.parent, nestingLevel)}
48
- `;
49
- }
50
- if (mdBlocks.children && mdBlocks.children.length > 0) {
51
- mdString += this.toMarkdownString(mdBlocks.children, nestingLevel + 1);
52
- }
53
- });
54
- return mdString;
55
- }
56
- /**
57
- * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
58
- * @param {string} id - notion page id (not database id)
59
- * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100 (Default=null)
60
- * @returns {Promise<MdBlock[]>} - List of markdown blocks
61
- */
62
- async pageToMarkdown(id, totalPage = null) {
63
- if (!this.notionClient) {
64
- throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
65
- }
66
- const blocks = await (0, notion_1.getBlockChildren)(this.notionClient, id, totalPage);
67
- const parsedData = await this.blocksToMarkdown(blocks);
68
- return parsedData;
69
- }
70
- /**
71
- * Converts list of Notion Blocks to Markdown Blocks
72
- * @param {ListBlockChildrenResponseResults | undefined} blocks - List of notion blocks
73
- * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100
74
- * @param {MdBlock[]} mdBlocks - Defines max depth of nesting
75
- * @returns {Promise<MdBlock[]>} - Array of markdown blocks with their children
76
- */
77
- async blocksToMarkdown(blocks, totalPage = null, mdBlocks = []) {
78
- if (!this.notionClient) {
79
- throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
80
- }
81
- if (!blocks)
82
- return mdBlocks;
83
- for (let i = 0; i < blocks.length; i++) {
84
- let block = blocks[i];
85
- if ("has_children" in block && block.has_children && block.type !== "column_list") {
86
- let child_blocks = await (0, notion_1.getBlockChildren)(this.notionClient, block.id, totalPage);
87
- mdBlocks.push({
88
- parent: await this.blockToMarkdown(block),
89
- children: [],
90
- });
91
- let l = mdBlocks.length;
92
- await this.blocksToMarkdown(child_blocks, totalPage, mdBlocks[l - 1].children);
93
- continue;
94
- }
95
- let tmp = await this.blockToMarkdown(block);
96
- mdBlocks.push({ parent: tmp, children: [] });
97
- }
98
- return mdBlocks;
99
- }
100
- /**
101
- * Converts a Notion Block to a Markdown Block
102
- * @param {ListBlockChildrenResponseResult} block - single notion block
103
- * @returns {string} corresponding markdown string of the passed block
104
- */
105
- async blockToMarkdown(block) {
106
- if (!("type" in block))
107
- return "";
108
- let parsedData = "";
109
- const { type } = block;
110
- // console.log({ block });
111
- switch (type) {
112
- case "image":
113
- {
114
- let blockContent = block.image;
115
- const image_caption_plain = blockContent.caption
116
- .map((item) => item.plain_text)
117
- .join("");
118
- const image_type = blockContent.type;
119
- if (image_type === "external")
120
- return md.image(image_caption_plain, blockContent.external.url);
121
- if (image_type === "file")
122
- return md.image(image_caption_plain, blockContent.file.url);
123
- }
124
- break;
125
- case "divider": {
126
- return md.divider();
127
- }
128
- case "equation": {
129
- return md.codeBlock(block.equation.expression);
130
- }
131
- case "video":
132
- case "file":
133
- case "pdf":
134
- {
135
- let blockContent;
136
- if (type === "video")
137
- blockContent = block.video;
138
- if (type === "file")
139
- blockContent = block.file;
140
- if (type === "pdf")
141
- blockContent = block.pdf;
142
- if (blockContent) {
143
- const file_type = blockContent.type;
144
- if (file_type === "external")
145
- return md.link("image", blockContent.external.url);
146
- if (file_type === "file")
147
- return md.link("image", blockContent.file.url);
148
- }
149
- }
150
- break;
151
- case "bookmark":
152
- case "embed":
153
- case "link_preview":
154
- case "link_to_page":
155
- {
156
- let blockContent;
157
- if (type === "bookmark")
158
- blockContent = block.bookmark;
159
- if (type === "embed")
160
- blockContent = block.embed;
161
- if (type === "link_preview")
162
- blockContent = block.link_preview;
163
- if (type === "link_to_page" && block.link_to_page.type === "page_id")
164
- blockContent = { url: block.link_to_page.page_id };
165
- if (blockContent)
166
- return md.link(type, blockContent.url);
167
- }
168
- break;
169
- case "table": {
170
- const { id, has_children } = block;
171
- let tableArr = [];
172
- if (has_children) {
173
- const tableRows = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
174
- // console.log(">>", tableRows);
175
- let rowsPromise = tableRows === null || tableRows === void 0 ? void 0 : tableRows.map(async (row) => {
176
- const { type } = row;
177
- const cells = row[type]["cells"];
178
- /**
179
- * this is more like a hack since matching the type text was
180
- * difficult. So converting each cell to paragraph type to
181
- * reuse the blockToMarkdown function
182
- */
183
- let cellStringPromise = cells.map(async (cell) => await this.blockToMarkdown({
184
- type: "paragraph",
185
- paragraph: { rich_text: cell },
186
- }));
187
- const cellStringArr = await Promise.all(cellStringPromise);
188
- // console.log("~~", cellStringArr);
189
- tableArr.push(cellStringArr);
190
- // console.log(tableArr);
191
- });
192
- await Promise.all(rowsPromise || []);
193
- }
194
- parsedData = md.table(tableArr);
195
- return parsedData;
196
- }
197
- case "column_list": {
198
- const { id, has_children } = block;
199
- if (!has_children)
200
- return "";
201
- const column_list_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
202
- let column_list_promise = column_list_children.map(async (column) => await this.blockToMarkdown(column));
203
- let column_list = await Promise.all(column_list_promise);
204
- // console.log(column_list);
205
- return column_list.join("\n\n");
206
- }
207
- case "column": {
208
- const { id, has_children } = block;
209
- if (!has_children)
210
- return "";
211
- const column_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
212
- const column_children_promise = column_children.map(async (column_child) => await this.blockToMarkdown(column_child));
213
- let column = await Promise.all(column_children_promise);
214
- return column.join("\n\n");
215
- }
216
- // Rest of the types
217
- // "paragraph"
218
- // "heading_1"
219
- // "heading_2"
220
- // "heading_3"
221
- // "bulleted_list_item"
222
- // "numbered_list_item"
223
- // "quote"
224
- // "to_do"
225
- // "toggle"
226
- // "template"
227
- // "synced_block"
228
- // "child_page"
229
- // "child_database"
230
- // "code"
231
- // "callout"
232
- // "breadcrumb"
233
- // "table_of_contents"
234
- // "column_list"
235
- // "column"
236
- // "link_to_page"
237
- // "audio"
238
- // "unsupported"
239
- default: {
240
- // In this case typescript is not able to index the types properly, hence ignoring the error
241
- // @ts-ignore
242
- let blockContent = block[type].text || block[type].rich_text || [];
243
- blockContent.map((content) => {
244
- const annotations = content.annotations;
245
- let plain_text = content.plain_text;
246
- plain_text = this.annotatePlainText(plain_text, annotations);
247
- if (content["href"])
248
- plain_text = md.link(plain_text, content["href"]);
249
- parsedData += plain_text;
250
- });
251
- }
252
- }
253
- switch (type) {
254
- case "code":
255
- {
256
- parsedData = md.codeBlock(parsedData, block[type].language);
257
- }
258
- break;
259
- case "heading_1":
260
- {
261
- parsedData = md.heading1(parsedData);
262
- }
263
- break;
264
- case "heading_2":
265
- {
266
- parsedData = md.heading2(parsedData);
267
- }
268
- break;
269
- case "heading_3":
270
- {
271
- parsedData = md.heading3(parsedData);
272
- }
273
- break;
274
- case "quote":
275
- {
276
- parsedData = md.quote(parsedData);
277
- }
278
- break;
279
- case "callout":
280
- {
281
- parsedData = md.callout(parsedData, block[type].icon);
282
- }
283
- break;
284
- case "bulleted_list_item":
285
- case "numbered_list_item":
286
- {
287
- parsedData = md.bullet(parsedData);
288
- }
289
- break;
290
- case "to_do":
291
- {
292
- parsedData = md.todo(parsedData, block.to_do.checked);
293
- }
294
- break;
295
- }
296
- return parsedData;
297
- }
298
- /**
299
- * Annoate text using provided annotations
300
- * @param {string} text - String to be annotated
301
- * @param {Annotations} annotations - Annotation object of a notion block
302
- * @returns {string} - Annotated text
303
- */
304
- annotatePlainText(text, annotations) {
305
- // if text is all spaces, don't annotate
306
- if (text.match(/^\s*$/))
307
- return text;
308
- const leadingSpaceMatch = text.match(/^(\s*)/);
309
- const trailingSpaceMatch = text.match(/(\s*)$/);
310
- const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : "";
311
- const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : "";
312
- text = text.trim();
313
- if (text !== "") {
314
- if (annotations.code)
315
- text = md.inlineCode(text);
316
- if (annotations.bold)
317
- text = md.bold(text);
318
- if (annotations.italic)
319
- text = md.italic(text);
320
- if (annotations.strikethrough)
321
- text = md.strikethrough(text);
322
- if (annotations.underline)
323
- text = md.underline(text);
324
- }
325
- return leading_space + text + trailing_space;
326
- }
327
- }
328
- exports.NotionToMarkdown = NotionToMarkdown;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NotionToMarkdown = void 0;
27
+ const md = __importStar(require("./utils/md"));
28
+ const notion_1 = require("./utils/notion");
29
+ /**
30
+ * Converts a Notion page to Markdown.
31
+ */
32
+ class NotionToMarkdown {
33
+ constructor(options) {
34
+ this.notionClient = options.notionClient;
35
+ this.customTransformers = {};
36
+ }
37
+ setCustomTransformer(type, transformer) {
38
+ this.customTransformers[type] = transformer;
39
+ return this;
40
+ }
41
+ /**
42
+ * Converts Markdown Blocks to string
43
+ * @param {MdBlock[]} mdBlocks - Array of markdown blocks
44
+ * @param {number} nestingLevel - Defines max depth of nesting
45
+ * @returns {string} - Returns markdown string
46
+ */
47
+ toMarkdownString(mdBlocks = [], nestingLevel = 0) {
48
+ let mdString = "";
49
+ mdBlocks.forEach((mdBlocks) => {
50
+ if (mdBlocks.parent) {
51
+ mdString += `
52
+ ${md.addTabSpace(mdBlocks.parent, nestingLevel)}
53
+ `;
54
+ }
55
+ if (mdBlocks.children && mdBlocks.children.length > 0) {
56
+ mdString += this.toMarkdownString(mdBlocks.children, nestingLevel + 1);
57
+ }
58
+ });
59
+ return mdString;
60
+ }
61
+ /**
62
+ * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
63
+ * @param {string} id - notion page id (not database id)
64
+ * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100 (Default=null)
65
+ * @returns {Promise<MdBlock[]>} - List of markdown blocks
66
+ */
67
+ async pageToMarkdown(id, totalPage = null) {
68
+ if (!this.notionClient) {
69
+ throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
70
+ }
71
+ const blocks = await (0, notion_1.getBlockChildren)(this.notionClient, id, totalPage);
72
+ const parsedData = await this.blocksToMarkdown(blocks);
73
+ return parsedData;
74
+ }
75
+ /**
76
+ * Converts list of Notion Blocks to Markdown Blocks
77
+ * @param {ListBlockChildrenResponseResults | undefined} blocks - List of notion blocks
78
+ * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100
79
+ * @param {MdBlock[]} mdBlocks - Defines max depth of nesting
80
+ * @returns {Promise<MdBlock[]>} - Array of markdown blocks with their children
81
+ */
82
+ async blocksToMarkdown(blocks, totalPage = null, mdBlocks = []) {
83
+ if (!this.notionClient) {
84
+ throw new Error("notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md");
85
+ }
86
+ if (!blocks)
87
+ return mdBlocks;
88
+ for (let i = 0; i < blocks.length; i++) {
89
+ let block = blocks[i];
90
+ if ("has_children" in block &&
91
+ block.has_children &&
92
+ block.type !== "column_list" &&
93
+ block.type !== "toggle") {
94
+ let child_blocks = await (0, notion_1.getBlockChildren)(this.notionClient, block.id, totalPage);
95
+ mdBlocks.push({
96
+ parent: await this.blockToMarkdown(block),
97
+ children: [],
98
+ });
99
+ let l = mdBlocks.length;
100
+ await this.blocksToMarkdown(child_blocks, totalPage, mdBlocks[l - 1].children);
101
+ continue;
102
+ }
103
+ let tmp = await this.blockToMarkdown(block);
104
+ mdBlocks.push({ parent: tmp, children: [] });
105
+ }
106
+ return mdBlocks;
107
+ }
108
+ /**
109
+ * Converts a Notion Block to a Markdown Block
110
+ * @param {ListBlockChildrenResponseResult} block - single notion block
111
+ * @returns {string} corresponding markdown string of the passed block
112
+ */
113
+ async blockToMarkdown(block) {
114
+ var _a;
115
+ if (typeof block !== "object" || !("type" in block))
116
+ return "";
117
+ let parsedData = "";
118
+ const { type } = block;
119
+ if (type in this.customTransformers && !!this.customTransformers[type])
120
+ return await this.customTransformers[type](block);
121
+ switch (type) {
122
+ case "image":
123
+ {
124
+ let blockContent = block.image;
125
+ const image_caption_plain = blockContent.caption
126
+ .map((item) => item.plain_text)
127
+ .join("");
128
+ const image_type = blockContent.type;
129
+ if (image_type === "external")
130
+ return md.image(image_caption_plain, blockContent.external.url);
131
+ if (image_type === "file")
132
+ return md.image(image_caption_plain, blockContent.file.url);
133
+ }
134
+ break;
135
+ case "divider": {
136
+ return md.divider();
137
+ }
138
+ case "equation": {
139
+ return md.codeBlock(block.equation.expression);
140
+ }
141
+ case "video":
142
+ case "file":
143
+ case "pdf":
144
+ {
145
+ let blockContent;
146
+ if (type === "video")
147
+ blockContent = block.video;
148
+ if (type === "file")
149
+ blockContent = block.file;
150
+ if (type === "pdf")
151
+ blockContent = block.pdf;
152
+ if (blockContent) {
153
+ const file_type = blockContent.type;
154
+ if (file_type === "external")
155
+ return md.link("image", blockContent.external.url);
156
+ if (file_type === "file")
157
+ return md.link("image", blockContent.file.url);
158
+ }
159
+ }
160
+ break;
161
+ case "bookmark":
162
+ case "embed":
163
+ case "link_preview":
164
+ case "link_to_page":
165
+ case "child_page":
166
+ case "child_database":
167
+ {
168
+ let blockContent;
169
+ let title = type;
170
+ if (type === "bookmark")
171
+ blockContent = block.bookmark;
172
+ if (type === "embed")
173
+ blockContent = block.embed;
174
+ if (type === "link_preview")
175
+ blockContent = block.link_preview;
176
+ if (type === "link_to_page" &&
177
+ block.link_to_page.type === "page_id") {
178
+ blockContent = { url: block.link_to_page.page_id };
179
+ }
180
+ if (type === "child_page") {
181
+ blockContent = { url: block.id };
182
+ title = block.child_page.title;
183
+ }
184
+ if (type === "child_database") {
185
+ blockContent = { url: block.id };
186
+ title = block.child_database.title || "child_database";
187
+ }
188
+ if (blockContent)
189
+ return md.link(title, blockContent.url);
190
+ }
191
+ break;
192
+ case "table": {
193
+ const { id, has_children } = block;
194
+ let tableArr = [];
195
+ if (has_children) {
196
+ const tableRows = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
197
+ // console.log(">>", tableRows);
198
+ let rowsPromise = tableRows === null || tableRows === void 0 ? void 0 : tableRows.map(async (row) => {
199
+ const { type } = row;
200
+ const cells = row[type]["cells"];
201
+ /**
202
+ * this is more like a hack since matching the type text was
203
+ * difficult. So converting each cell to paragraph type to
204
+ * reuse the blockToMarkdown function
205
+ */
206
+ let cellStringPromise = cells.map(async (cell) => await this.blockToMarkdown({
207
+ type: "paragraph",
208
+ paragraph: { rich_text: cell },
209
+ }));
210
+ const cellStringArr = await Promise.all(cellStringPromise);
211
+ // console.log("~~", cellStringArr);
212
+ tableArr.push(cellStringArr);
213
+ // console.log(tableArr);
214
+ });
215
+ await Promise.all(rowsPromise || []);
216
+ }
217
+ return md.table(tableArr);
218
+ }
219
+ case "column_list": {
220
+ const { id, has_children } = block;
221
+ if (!has_children)
222
+ return "";
223
+ const column_list_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
224
+ let column_list_promise = column_list_children.map(async (column) => await this.blockToMarkdown(column));
225
+ let column_list = await Promise.all(column_list_promise);
226
+ return column_list.join("\n\n");
227
+ }
228
+ case "column": {
229
+ const { id, has_children } = block;
230
+ if (!has_children)
231
+ return "";
232
+ const column_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
233
+ const column_children_promise = column_children.map(async (column_child) => await this.blockToMarkdown(column_child));
234
+ let column = await Promise.all(column_children_promise);
235
+ return column.join("\n\n");
236
+ }
237
+ case "toggle": {
238
+ const { id, has_children } = block;
239
+ const toggle_summary = (_a = block.toggle.rich_text[0]) === null || _a === void 0 ? void 0 : _a.plain_text;
240
+ // empty toggle
241
+ if (!has_children) {
242
+ return md.toggle(toggle_summary);
243
+ }
244
+ const toggle_children_object = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
245
+ // parse children blocks to md object
246
+ const toggle_children = await this.blocksToMarkdown(toggle_children_object);
247
+ // convert children md object to md string
248
+ const toggle_children_md_string = this.toMarkdownString(toggle_children);
249
+ return md.toggle(toggle_summary, toggle_children_md_string);
250
+ }
251
+ // Rest of the types
252
+ // "paragraph"
253
+ // "heading_1"
254
+ // "heading_2"
255
+ // "heading_3"
256
+ // "bulleted_list_item"
257
+ // "numbered_list_item"
258
+ // "quote"
259
+ // "to_do"
260
+ // "template"
261
+ // "synced_block"
262
+ // "child_page"
263
+ // "child_database"
264
+ // "code"
265
+ // "callout"
266
+ // "breadcrumb"
267
+ // "table_of_contents"
268
+ // "column_list"
269
+ // "column"
270
+ // "link_to_page"
271
+ // "audio"
272
+ // "unsupported"
273
+ default: {
274
+ // In this case typescript is not able to index the types properly, hence ignoring the error
275
+ // @ts-ignore
276
+ let blockContent = block[type].text || block[type].rich_text || [];
277
+ blockContent.map((content) => {
278
+ const annotations = content.annotations;
279
+ let plain_text = content.plain_text;
280
+ plain_text = this.annotatePlainText(plain_text, annotations);
281
+ if (content["href"])
282
+ plain_text = md.link(plain_text, content["href"]);
283
+ parsedData += plain_text;
284
+ });
285
+ }
286
+ }
287
+ switch (type) {
288
+ case "code":
289
+ {
290
+ parsedData = md.codeBlock(parsedData, block[type].language);
291
+ }
292
+ break;
293
+ case "heading_1":
294
+ {
295
+ parsedData = md.heading1(parsedData);
296
+ }
297
+ break;
298
+ case "heading_2":
299
+ {
300
+ parsedData = md.heading2(parsedData);
301
+ }
302
+ break;
303
+ case "heading_3":
304
+ {
305
+ parsedData = md.heading3(parsedData);
306
+ }
307
+ break;
308
+ case "quote":
309
+ {
310
+ parsedData = md.quote(parsedData);
311
+ }
312
+ break;
313
+ case "callout":
314
+ {
315
+ parsedData = md.callout(parsedData, block[type].icon);
316
+ }
317
+ break;
318
+ case "bulleted_list_item":
319
+ {
320
+ parsedData = md.bullet(parsedData);
321
+ }
322
+ break;
323
+ case "numbered_list_item":
324
+ {
325
+ parsedData = md.bullet(parsedData, block.numbered_list_item.number);
326
+ }
327
+ break;
328
+ case "to_do":
329
+ {
330
+ parsedData = md.todo(parsedData, block.to_do.checked);
331
+ }
332
+ break;
333
+ }
334
+ return parsedData;
335
+ }
336
+ /**
337
+ * Annoate text using provided annotations
338
+ * @param {string} text - String to be annotated
339
+ * @param {Annotations} annotations - Annotation object of a notion block
340
+ * @returns {string} - Annotated text
341
+ */
342
+ annotatePlainText(text, annotations) {
343
+ // if text is all spaces, don't annotate
344
+ if (text.match(/^\s*$/))
345
+ return text;
346
+ const leadingSpaceMatch = text.match(/^(\s*)/);
347
+ const trailingSpaceMatch = text.match(/(\s*)$/);
348
+ const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : "";
349
+ const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : "";
350
+ text = text.trim();
351
+ if (text !== "") {
352
+ if (annotations.code)
353
+ text = md.inlineCode(text);
354
+ if (annotations.bold)
355
+ text = md.bold(text);
356
+ if (annotations.italic)
357
+ text = md.italic(text);
358
+ if (annotations.strikethrough)
359
+ text = md.strikethrough(text);
360
+ if (annotations.underline)
361
+ text = md.underline(text);
362
+ }
363
+ return leading_space + text + trailing_space;
364
+ }
365
+ }
366
+ exports.NotionToMarkdown = NotionToMarkdown;
329
367
  //# sourceMappingURL=notion-to-md.js.map