notion-to-md 2.3.4 → 2.4.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,356 @@
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
+ }
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 &&
86
+ block.has_children &&
87
+ block.type !== "column_list" &&
88
+ block.type !== "toggle") {
89
+ let child_blocks = await (0, notion_1.getBlockChildren)(this.notionClient, block.id, totalPage);
90
+ mdBlocks.push({
91
+ parent: await this.blockToMarkdown(block),
92
+ children: [],
93
+ });
94
+ let l = mdBlocks.length;
95
+ await this.blocksToMarkdown(child_blocks, totalPage, mdBlocks[l - 1].children);
96
+ continue;
97
+ }
98
+ let tmp = await this.blockToMarkdown(block);
99
+ mdBlocks.push({ parent: tmp, children: [] });
100
+ }
101
+ return mdBlocks;
102
+ }
103
+ /**
104
+ * Converts a Notion Block to a Markdown Block
105
+ * @param {ListBlockChildrenResponseResult} block - single notion block
106
+ * @returns {string} corresponding markdown string of the passed block
107
+ */
108
+ async blockToMarkdown(block) {
109
+ if (!("type" in block))
110
+ return "";
111
+ let parsedData = "";
112
+ const { type } = block;
113
+ // console.log({ block });
114
+ switch (type) {
115
+ case "image":
116
+ {
117
+ let blockContent = block.image;
118
+ const image_caption_plain = blockContent.caption
119
+ .map((item) => item.plain_text)
120
+ .join("");
121
+ const image_type = blockContent.type;
122
+ if (image_type === "external")
123
+ return md.image(image_caption_plain, blockContent.external.url);
124
+ if (image_type === "file")
125
+ return md.image(image_caption_plain, blockContent.file.url);
126
+ }
127
+ break;
128
+ case "divider": {
129
+ return md.divider();
130
+ }
131
+ case "equation": {
132
+ return md.codeBlock(block.equation.expression);
133
+ }
134
+ case "video":
135
+ case "file":
136
+ case "pdf":
137
+ {
138
+ let blockContent;
139
+ if (type === "video")
140
+ blockContent = block.video;
141
+ if (type === "file")
142
+ blockContent = block.file;
143
+ if (type === "pdf")
144
+ blockContent = block.pdf;
145
+ if (blockContent) {
146
+ const file_type = blockContent.type;
147
+ if (file_type === "external")
148
+ return md.link("image", blockContent.external.url);
149
+ if (file_type === "file")
150
+ return md.link("image", blockContent.file.url);
151
+ }
152
+ }
153
+ break;
154
+ case "bookmark":
155
+ case "embed":
156
+ case "link_preview":
157
+ case "link_to_page":
158
+ case "child_page":
159
+ case "child_database":
160
+ {
161
+ let blockContent;
162
+ let title = type;
163
+ if (type === "bookmark")
164
+ blockContent = block.bookmark;
165
+ if (type === "embed")
166
+ blockContent = block.embed;
167
+ if (type === "link_preview")
168
+ blockContent = block.link_preview;
169
+ if (type === "link_to_page" &&
170
+ block.link_to_page.type === "page_id") {
171
+ blockContent = { url: block.link_to_page.page_id };
172
+ }
173
+ if (type === "child_page") {
174
+ blockContent = { url: block.id };
175
+ title = block.child_page.title;
176
+ }
177
+ if (type === "child_database") {
178
+ blockContent = { url: block.id };
179
+ title = block.child_database.title || "child_database";
180
+ }
181
+ if (blockContent)
182
+ return md.link(title, blockContent.url);
183
+ }
184
+ break;
185
+ case "table": {
186
+ const { id, has_children } = block;
187
+ let tableArr = [];
188
+ if (has_children) {
189
+ const tableRows = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
190
+ // console.log(">>", tableRows);
191
+ let rowsPromise = tableRows === null || tableRows === void 0 ? void 0 : tableRows.map(async (row) => {
192
+ const { type } = row;
193
+ const cells = row[type]["cells"];
194
+ /**
195
+ * this is more like a hack since matching the type text was
196
+ * difficult. So converting each cell to paragraph type to
197
+ * reuse the blockToMarkdown function
198
+ */
199
+ let cellStringPromise = cells.map(async (cell) => await this.blockToMarkdown({
200
+ type: "paragraph",
201
+ paragraph: { rich_text: cell },
202
+ }));
203
+ const cellStringArr = await Promise.all(cellStringPromise);
204
+ // console.log("~~", cellStringArr);
205
+ tableArr.push(cellStringArr);
206
+ // console.log(tableArr);
207
+ });
208
+ await Promise.all(rowsPromise || []);
209
+ }
210
+ return md.table(tableArr);
211
+ }
212
+ case "column_list": {
213
+ const { id, has_children } = block;
214
+ if (!has_children)
215
+ return "";
216
+ const column_list_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
217
+ let column_list_promise = column_list_children.map(async (column) => await this.blockToMarkdown(column));
218
+ let column_list = await Promise.all(column_list_promise);
219
+ return column_list.join("\n\n");
220
+ }
221
+ case "column": {
222
+ const { id, has_children } = block;
223
+ if (!has_children)
224
+ return "";
225
+ const column_children = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
226
+ const column_children_promise = column_children.map(async (column_child) => await this.blockToMarkdown(column_child));
227
+ let column = await Promise.all(column_children_promise);
228
+ return column.join("\n\n");
229
+ }
230
+ case "toggle": {
231
+ const { id, has_children } = block;
232
+ const toggle_summary = block.toggle.rich_text[0].plain_text;
233
+ // empty toggle
234
+ if (!has_children) {
235
+ return md.toggle(toggle_summary);
236
+ }
237
+ const toggle_children_object = await (0, notion_1.getBlockChildren)(this.notionClient, id, 100);
238
+ // parse children blocks to md object
239
+ const toggle_children = await this.blocksToMarkdown(toggle_children_object);
240
+ // convert children md object to md string
241
+ const toggle_children_md_string = this.toMarkdownString(toggle_children);
242
+ return md.toggle(toggle_summary, toggle_children_md_string);
243
+ }
244
+ // Rest of the types
245
+ // "paragraph"
246
+ // "heading_1"
247
+ // "heading_2"
248
+ // "heading_3"
249
+ // "bulleted_list_item"
250
+ // "numbered_list_item"
251
+ // "quote"
252
+ // "to_do"
253
+ // "template"
254
+ // "synced_block"
255
+ // "child_page"
256
+ // "child_database"
257
+ // "code"
258
+ // "callout"
259
+ // "breadcrumb"
260
+ // "table_of_contents"
261
+ // "column_list"
262
+ // "column"
263
+ // "link_to_page"
264
+ // "audio"
265
+ // "unsupported"
266
+ default: {
267
+ // In this case typescript is not able to index the types properly, hence ignoring the error
268
+ // @ts-ignore
269
+ let blockContent = block[type].text || block[type].rich_text || [];
270
+ blockContent.map((content) => {
271
+ const annotations = content.annotations;
272
+ let plain_text = content.plain_text;
273
+ plain_text = this.annotatePlainText(plain_text, annotations);
274
+ if (content["href"])
275
+ plain_text = md.link(plain_text, content["href"]);
276
+ parsedData += plain_text;
277
+ });
278
+ }
279
+ }
280
+ switch (type) {
281
+ case "code":
282
+ {
283
+ parsedData = md.codeBlock(parsedData, block[type].language);
284
+ }
285
+ break;
286
+ case "heading_1":
287
+ {
288
+ parsedData = md.heading1(parsedData);
289
+ }
290
+ break;
291
+ case "heading_2":
292
+ {
293
+ parsedData = md.heading2(parsedData);
294
+ }
295
+ break;
296
+ case "heading_3":
297
+ {
298
+ parsedData = md.heading3(parsedData);
299
+ }
300
+ break;
301
+ case "quote":
302
+ {
303
+ parsedData = md.quote(parsedData);
304
+ }
305
+ break;
306
+ case "callout":
307
+ {
308
+ parsedData = md.callout(parsedData, block[type].icon);
309
+ }
310
+ break;
311
+ case "bulleted_list_item":
312
+ case "numbered_list_item":
313
+ {
314
+ parsedData = md.bullet(parsedData);
315
+ }
316
+ break;
317
+ case "to_do":
318
+ {
319
+ parsedData = md.todo(parsedData, block.to_do.checked);
320
+ }
321
+ break;
322
+ }
323
+ return parsedData;
324
+ }
325
+ /**
326
+ * Annoate text using provided annotations
327
+ * @param {string} text - String to be annotated
328
+ * @param {Annotations} annotations - Annotation object of a notion block
329
+ * @returns {string} - Annotated text
330
+ */
331
+ annotatePlainText(text, annotations) {
332
+ // if text is all spaces, don't annotate
333
+ if (text.match(/^\s*$/))
334
+ return text;
335
+ const leadingSpaceMatch = text.match(/^(\s*)/);
336
+ const trailingSpaceMatch = text.match(/(\s*)$/);
337
+ const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : "";
338
+ const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : "";
339
+ text = text.trim();
340
+ if (text !== "") {
341
+ if (annotations.code)
342
+ text = md.inlineCode(text);
343
+ if (annotations.bold)
344
+ text = md.bold(text);
345
+ if (annotations.italic)
346
+ text = md.italic(text);
347
+ if (annotations.strikethrough)
348
+ text = md.strikethrough(text);
349
+ if (annotations.underline)
350
+ text = md.underline(text);
351
+ }
352
+ return leading_space + text + trailing_space;
353
+ }
354
+ }
355
+ exports.NotionToMarkdown = NotionToMarkdown;
329
356
  //# sourceMappingURL=notion-to-md.js.map