notion-to-md 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/notion-to-md.d.ts +3 -3
- package/build/notion-to-md.d.ts.map +1 -1
- package/build/notion-to-md.js +39 -31
- package/build/notion-to-md.js.map +1 -1
- package/build/types/index.d.ts +2 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js.map +1 -1
- package/package.json +1 -3
- 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/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;IAU5C,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;IA+FjB;;;;;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;IAkDrB;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,+BAA+B;IA0P5D;;;;;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,7 @@ class NotionToMarkdown {
|
|
|
36
33
|
constructor(options) {
|
|
37
34
|
this.notionClient = options.notionClient;
|
|
38
35
|
const defaultConfig = {
|
|
39
|
-
|
|
40
|
-
saveToDir: ".",
|
|
36
|
+
separateChildPage: false,
|
|
41
37
|
};
|
|
42
38
|
this.targetPage = "";
|
|
43
39
|
this.config = { ...defaultConfig, ...options.config };
|
|
@@ -51,24 +47,30 @@ class NotionToMarkdown {
|
|
|
51
47
|
* Converts Markdown Blocks to string
|
|
52
48
|
* @param {MdBlock[]} mdBlocks - Array of markdown blocks
|
|
53
49
|
* @param {number} nestingLevel - Defines max depth of nesting
|
|
54
|
-
* @returns {
|
|
50
|
+
* @returns {MdStringObject} - Returns markdown string with child pages separated
|
|
55
51
|
*/
|
|
56
|
-
toMarkdownString(mdBlocks = [],
|
|
57
|
-
let
|
|
52
|
+
toMarkdownString(mdBlocks = [], pageIdentifier = "parent", nestingLevel = 0) {
|
|
53
|
+
let mdOutput = {};
|
|
58
54
|
mdBlocks.forEach((mdBlocks) => {
|
|
59
55
|
// NOTE: toggle in the child blocks logic
|
|
60
56
|
// adding a toggle check prevents duplicate
|
|
61
57
|
// rendering of toggle title
|
|
62
58
|
// process parent blocks
|
|
63
|
-
if (mdBlocks.parent &&
|
|
59
|
+
if (mdBlocks.parent &&
|
|
60
|
+
mdBlocks.type !== "toggle" &&
|
|
61
|
+
mdBlocks.type !== "child_page") {
|
|
64
62
|
if (mdBlocks.type !== "to_do" &&
|
|
65
63
|
mdBlocks.type !== "bulleted_list_item" &&
|
|
66
64
|
mdBlocks.type !== "numbered_list_item") {
|
|
65
|
+
// initialize if key doesn't exist
|
|
66
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
67
67
|
// add extra line breaks non list blocks
|
|
68
|
-
|
|
68
|
+
mdOutput[pageIdentifier] += `\n${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n\n`;
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
|
|
71
|
+
// initialize if key doesn't exist
|
|
72
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
73
|
+
mdOutput[pageIdentifier] += `${md.addTabSpace(mdBlocks.parent, nestingLevel)}\n`;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
// process child blocks
|
|
@@ -76,36 +78,44 @@ class NotionToMarkdown {
|
|
|
76
78
|
if (mdBlocks.type === "synced_block" ||
|
|
77
79
|
mdBlocks.type === "column_list" ||
|
|
78
80
|
mdBlocks.type === "column") {
|
|
79
|
-
let mdstr = this.toMarkdownString(mdBlocks.children);
|
|
80
|
-
|
|
81
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier);
|
|
82
|
+
// mdOutput[pageIdentifier] += mdstr[pageIdentifier];
|
|
83
|
+
mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || "";
|
|
84
|
+
Object.keys(mdstr).forEach((key) => {
|
|
85
|
+
if (mdOutput[key]) {
|
|
86
|
+
mdOutput[key] + mdstr[key];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
mdOutput[key] = mdstr[key];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
mdOutput[pageIdentifier] += mdstr[pageIdentifier];
|
|
93
|
+
// mdOutput = { ...mdOutput, ...mdstr };
|
|
81
94
|
}
|
|
82
95
|
else if (mdBlocks.type === "child_page") {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
(0, fs_extra_1.ensureFile)(filePath).then(() => {
|
|
90
|
-
(0, fs_extra_1.writeFile)(filePath, mdstr);
|
|
91
|
-
});
|
|
96
|
+
const childPageTitle = mdBlocks.parent;
|
|
97
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, childPageTitle);
|
|
98
|
+
if (this.config.separateChildPage) {
|
|
99
|
+
// console.log("<<", mdOutput, mdstr);
|
|
100
|
+
mdOutput = { ...mdOutput, ...mdstr };
|
|
101
|
+
// console.log(">>", mdOutput, "\n\n");
|
|
92
102
|
}
|
|
93
103
|
else {
|
|
94
|
-
|
|
104
|
+
mdOutput[pageIdentifier] += mdstr[childPageTitle];
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
else if (mdBlocks.type === "toggle") {
|
|
98
108
|
// convert children md object to md string
|
|
99
109
|
const toggle_children_md_string = this.toMarkdownString(mdBlocks.children);
|
|
100
|
-
|
|
110
|
+
mdOutput[pageIdentifier] += md.toggle(mdBlocks.parent, toggle_children_md_string["parent"]);
|
|
101
111
|
}
|
|
102
112
|
else {
|
|
103
|
-
let mdstr = this.toMarkdownString(mdBlocks.children,
|
|
104
|
-
|
|
113
|
+
let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier, nestingLevel + 1);
|
|
114
|
+
mdOutput[pageIdentifier] += mdstr["parent"];
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
});
|
|
108
|
-
return
|
|
118
|
+
return mdOutput;
|
|
109
119
|
}
|
|
110
120
|
/**
|
|
111
121
|
* Retrieves Notion Blocks based on ID and converts them to Markdown Blocks
|
|
@@ -242,10 +252,8 @@ class NotionToMarkdown {
|
|
|
242
252
|
case "child_page":
|
|
243
253
|
{
|
|
244
254
|
let pageTitle = block.child_page.title;
|
|
245
|
-
if (this.config.
|
|
246
|
-
|
|
247
|
-
const filePath = `${fileName}.md`;
|
|
248
|
-
return md.link(pageTitle, filePath);
|
|
255
|
+
if (this.config.separateChildPage) {
|
|
256
|
+
return pageTitle;
|
|
249
257
|
}
|
|
250
258
|
return md.heading2(pageTitle);
|
|
251
259
|
}
|
|
@@ -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;IAED;;;;;OAKG;IACH,gBAAgB,CACd,WAAsB,EAAE,EACxB,QAAiB,EACjB,eAAuB,CAAC;QAExB,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5B,yCAAyC;YACzC,2CAA2C;YAC3C,4BAA4B;YAE5B,wBAAwB;YACxB,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACjD,IACE,QAAQ,CAAC,IAAI,KAAK,OAAO;oBACzB,QAAQ,CAAC,IAAI,KAAK,oBAAoB;oBACtC,QAAQ,CAAC,IAAI,KAAK,oBAAoB,EACtC;o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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;SACzB,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACtD,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;IAC/B,CAAC;IAED,oBAAoB,CAClB,IAAY,EACZ,WAA8B;QAE9B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CACd,WAAsB,EAAE,EACxB,iBAAyB,QAAQ,EACjC,eAAuB,CAAC;QAExB,IAAI,QAAQ,GAAmB,EAAE,CAAC;QAElC,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5B,yCAAyC;YACzC,2CAA2C;YAC3C,4BAA4B;YAE5B,wBAAwB;YACxB,IACE,QAAQ,CAAC,MAAM;gBACf,QAAQ,CAAC,IAAI,KAAK,QAAQ;gBAC1B,QAAQ,CAAC,IAAI,KAAK,YAAY,EAC9B;gBACA,IACE,QAAQ,CAAC,IAAI,KAAK,OAAO;oBACzB,QAAQ,CAAC,IAAI,KAAK,oBAAoB;oBACtC,QAAQ,CAAC,IAAI,KAAK,oBAAoB,EACtC;oBACA,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,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhD,MAAM,aAAa,GAAG,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,cAAc,GAAG,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEvE,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACjD,IAAI,WAAW,CAAC,IAAI;gBAAE,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,WAAW,CAAC,MAAM;gBAAE,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,WAAW,CAAC,aAAa;gBAAE,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC7D,IAAI,WAAW,CAAC,SAAS;gBAAE,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACtD;QAED,OAAO,aAAa,GAAG,IAAI,GAAG,cAAc,CAAC;IAC/C,CAAC;CACF;AAjfD,4CAifC","sourcesContent":["import { Client } from \"@notionhq/client\";\n\nimport {\n Annotations,\n CustomTransformer,\n ListBlockChildrenResponseResult,\n ListBlockChildrenResponseResults,\n MdBlock,\n NotionToMarkdownOptions,\n Equation,\n Text,\n ConfigurationOptions,\n MdStringObject,\n} from \"./types\";\nimport * as md from \"./utils/md\";\nimport { getBlockChildren } from \"./utils/notion\";\n\n/**\n * Converts a Notion page to Markdown.\n */\nexport class NotionToMarkdown {\n private notionClient: Client;\n private config: ConfigurationOptions;\n private targetPage: string;\n private customTransformers: Record<string, CustomTransformer>;\n\n constructor(options: NotionToMarkdownOptions) {\n this.notionClient = options.notionClient;\n const defaultConfig: ConfigurationOptions = {\n separateChildPage: false,\n };\n this.targetPage = \"\";\n this.config = { ...defaultConfig, ...options.config };\n this.customTransformers = {};\n }\n\n setCustomTransformer(\n type: string,\n transformer: CustomTransformer\n ): NotionToMarkdown {\n this.customTransformers[type] = transformer;\n\n return this;\n }\n\n /**\n * Converts Markdown Blocks to string\n * @param {MdBlock[]} mdBlocks - Array of markdown blocks\n * @param {number} nestingLevel - Defines max depth of nesting\n * @returns {MdStringObject} - Returns markdown string with child pages separated\n */\n toMarkdownString(\n mdBlocks: MdBlock[] = [],\n pageIdentifier: string = \"parent\",\n nestingLevel: number = 0\n ): MdStringObject {\n let mdOutput: MdStringObject = {};\n\n mdBlocks.forEach((mdBlocks) => {\n // NOTE: toggle in the child blocks logic\n // adding a toggle check prevents duplicate\n // rendering of toggle title\n\n // process parent blocks\n if (\n mdBlocks.parent &&\n mdBlocks.type !== \"toggle\" &&\n mdBlocks.type !== \"child_page\"\n ) {\n if (\n mdBlocks.type !== \"to_do\" &&\n mdBlocks.type !== \"bulleted_list_item\" &&\n mdBlocks.type !== \"numbered_list_item\"\n ) {\n // initialize if key doesn't exist\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n // add extra line breaks non list blocks\n mdOutput[pageIdentifier] += `\\n${md.addTabSpace(\n mdBlocks.parent,\n nestingLevel\n )}\\n\\n`;\n } else {\n // initialize if key doesn't exist\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n mdOutput[pageIdentifier] += `${md.addTabSpace(\n mdBlocks.parent,\n nestingLevel\n )}\\n`;\n }\n }\n\n // process child blocks\n if (mdBlocks.children && mdBlocks.children.length > 0) {\n if (\n mdBlocks.type === \"synced_block\" ||\n mdBlocks.type === \"column_list\" ||\n mdBlocks.type === \"column\"\n ) {\n let mdstr = this.toMarkdownString(mdBlocks.children, pageIdentifier);\n // mdOutput[pageIdentifier] += mdstr[pageIdentifier];\n mdOutput[pageIdentifier] = mdOutput[pageIdentifier] || \"\";\n\n Object.keys(mdstr).forEach((key) => {\n if (mdOutput[key]) {\n mdOutput[key] + mdstr[key];\n } else {\n mdOutput[key] = mdstr[key];\n }\n });\n mdOutput[pageIdentifier] += mdstr[pageIdentifier];\n\n // mdOutput = { ...mdOutput, ...mdstr };\n } else if (mdBlocks.type === \"child_page\") {\n const childPageTitle = mdBlocks.parent;\n let mdstr = this.toMarkdownString(mdBlocks.children, childPageTitle);\n\n if (this.config.separateChildPage) {\n // console.log(\"<<\", mdOutput, mdstr);\n mdOutput = { ...mdOutput, ...mdstr };\n // console.log(\">>\", mdOutput, \"\\n\\n\");\n } else {\n mdOutput[pageIdentifier] += mdstr[childPageTitle];\n }\n } else if (mdBlocks.type === \"toggle\") {\n // convert children md object to md string\n const toggle_children_md_string = this.toMarkdownString(\n mdBlocks.children\n );\n\n mdOutput[pageIdentifier] += md.toggle(\n mdBlocks.parent,\n toggle_children_md_string[\"parent\"]\n );\n } else {\n let mdstr = this.toMarkdownString(\n mdBlocks.children,\n pageIdentifier,\n nestingLevel + 1\n );\n\n mdOutput[pageIdentifier] += mdstr[\"parent\"];\n }\n }\n });\n\n return mdOutput;\n }\n\n /**\n * Retrieves Notion Blocks based on ID and converts them to Markdown Blocks\n * @param {string} id - notion page id (not database id)\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100 (Default=null)\n * @returns {Promise<MdBlock[]>} - List of markdown blocks\n */\n async pageToMarkdown(\n id: string,\n totalPage: number | null = null\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n this.targetPage = id;\n const blocks = await getBlockChildren(this.notionClient, id, totalPage);\n\n const parsedData = await this.blocksToMarkdown(blocks);\n\n return parsedData;\n }\n\n /**\n * Converts list of Notion Blocks to Markdown Blocks\n * @param {ListBlockChildrenResponseResults | undefined} blocks - List of notion blocks\n * @param {number} totalPage - Retrieve block children request number, page_size Maximum = totalPage * 100\n * @param {MdBlock[]} mdBlocks - Defines max depth of nesting\n * @returns {Promise<MdBlock[]>} - Array of markdown blocks with their children\n */\n async blocksToMarkdown(\n blocks?: ListBlockChildrenResponseResults,\n totalPage: number | null = null,\n mdBlocks: MdBlock[] = []\n ): Promise<MdBlock[]> {\n if (!this.notionClient) {\n throw new Error(\n \"notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md\"\n );\n }\n\n if (!blocks) return mdBlocks;\n\n for (let i = 0; i < blocks.length; i++) {\n let block = blocks[i];\n\n if (\"has_children\" in block && block.has_children) {\n // Get children of this block.\n let child_blocks = await getBlockChildren(\n this.notionClient,\n block.id,\n totalPage\n );\n\n // Push this block to mdBlocks.\n mdBlocks.push({\n type: block.type,\n blockId: block.id,\n parent: await this.blockToMarkdown(block),\n children: [],\n });\n\n // Recursively call blocksToMarkdown to get children of this block.\n let l = mdBlocks.length;\n await this.blocksToMarkdown(\n child_blocks,\n totalPage,\n mdBlocks[l - 1].children\n );\n continue;\n }\n\n let tmp = await this.blockToMarkdown(block);\n mdBlocks.push({\n // @ts-ignore\n type: block.type,\n blockId: block.id,\n parent: tmp,\n children: [],\n });\n }\n return mdBlocks;\n }\n\n /**\n * Converts a Notion Block to a Markdown Block\n * @param {ListBlockChildrenResponseResult} block - single notion block\n * @returns {string} corresponding markdown string of the passed block\n */\n async blockToMarkdown(block: ListBlockChildrenResponseResult) {\n if (typeof block !== \"object\" || !(\"type\" in block)) return \"\";\n\n let parsedData = \"\";\n const { type } = block;\n if (type in this.customTransformers && !!this.customTransformers[type]) {\n const customTransformerValue = await this.customTransformers[type](block);\n if (!!customTransformerValue || customTransformerValue === \"\")\n return customTransformerValue;\n }\n\n switch (type) {\n case \"image\":\n {\n let blockContent = block.image;\n\n const image_caption_plain = blockContent.caption\n .map((item: any) => item.plain_text)\n .join(\"\");\n\n const image_type = blockContent.type;\n\n if (image_type === \"external\")\n return md.image(image_caption_plain, blockContent.external.url);\n\n if (image_type === \"file\")\n return md.image(image_caption_plain, blockContent.file.url);\n }\n break;\n\n case \"divider\": {\n return md.divider();\n }\n\n case \"equation\": {\n return md.equation(block.equation.expression);\n }\n\n case \"video\":\n case \"file\":\n case \"pdf\":\n {\n let blockContent;\n if (type === \"video\") blockContent = block.video;\n if (type === \"file\") blockContent = block.file;\n if (type === \"pdf\") blockContent = block.pdf;\n if (blockContent) {\n const file_type = blockContent.type;\n if (file_type === \"external\")\n return md.link(\"image\", blockContent.external.url);\n if (file_type === \"file\")\n return md.link(\"image\", blockContent.file.url);\n }\n }\n break;\n\n case \"bookmark\":\n case \"embed\":\n case \"link_preview\":\n case \"link_to_page\":\n {\n let blockContent;\n let title: string = type;\n if (type === \"bookmark\") blockContent = block.bookmark;\n if (type === \"embed\") blockContent = block.embed;\n if (type === \"link_preview\") blockContent = block.link_preview;\n if (\n type === \"link_to_page\" &&\n block.link_to_page.type === \"page_id\"\n ) {\n blockContent = { url: block.link_to_page.page_id };\n }\n\n if (blockContent) return md.link(title, blockContent.url);\n }\n break;\n\n case \"child_page\":\n {\n let pageTitle: string = block.child_page.title;\n\n if (this.config.separateChildPage) {\n return pageTitle;\n }\n\n return md.heading2(pageTitle);\n }\n break;\n case \"child_database\":\n {\n let pageTitle = block.child_database.title || `child_database`;\n return pageTitle;\n }\n break;\n\n case \"table\": {\n const { id, has_children } = block;\n let tableArr: string[][] = [];\n if (has_children) {\n const tableRows = await getBlockChildren(this.notionClient, id, 100);\n let rowsPromise = tableRows?.map(async (row) => {\n const { type } = row as any;\n const cells = (row as any)[type][\"cells\"];\n\n /**\n * this is more like a hack since matching the type text was\n * difficult. So converting each cell to paragraph type to\n * reuse the blockToMarkdown function\n */\n let cellStringPromise = cells.map(\n async (cell: any) =>\n await this.blockToMarkdown({\n type: \"paragraph\",\n paragraph: { rich_text: cell },\n } as ListBlockChildrenResponseResult)\n );\n\n const cellStringArr = await Promise.all(cellStringPromise);\n tableArr.push(cellStringArr);\n });\n await Promise.all(rowsPromise || []);\n }\n return md.table(tableArr);\n }\n // Rest of the types\n // \"paragraph\"\n // \"heading_1\"\n // \"heading_2\"\n // \"heading_3\"\n // \"bulleted_list_item\"\n // \"numbered_list_item\"\n // \"quote\"\n // \"to_do\"\n // \"template\"\n // \"synced_block\"\n // \"child_page\"\n // \"child_database\"\n // \"code\"\n // \"callout\"\n // \"breadcrumb\"\n // \"table_of_contents\"\n // \"link_to_page\"\n // \"audio\"\n // \"unsupported\"\n\n default: {\n // In this case typescript is not able to index the types properly, hence ignoring the error\n // @ts-ignore\n let blockContent = block[type].text || block[type].rich_text || [];\n blockContent.map((content: Text | Equation) => {\n if (content.type === \"equation\") {\n parsedData += md.inlineEquation(content.equation.expression);\n return;\n }\n\n const annotations = content.annotations;\n let plain_text = content.plain_text;\n\n plain_text = this.annotatePlainText(plain_text, annotations);\n\n if (content[\"href\"])\n plain_text = md.link(plain_text, content[\"href\"]);\n\n parsedData += plain_text;\n });\n }\n }\n\n switch (type) {\n case \"code\":\n {\n parsedData = md.codeBlock(parsedData, block[type].language);\n }\n break;\n\n case \"heading_1\":\n {\n parsedData = md.heading1(parsedData);\n }\n break;\n\n case \"heading_2\":\n {\n parsedData = md.heading2(parsedData);\n }\n break;\n\n case \"heading_3\":\n {\n parsedData = md.heading3(parsedData);\n }\n break;\n\n case \"quote\":\n {\n parsedData = md.quote(parsedData);\n }\n break;\n\n case \"callout\":\n {\n const { id, has_children } = block;\n let callout_string = \"\";\n\n if (!has_children) {\n return md.callout(parsedData, block[type].icon);\n }\n\n const callout_children_object = await getBlockChildren(\n this.notionClient,\n id,\n 100\n );\n\n // // parse children blocks to md object\n const callout_children = await this.blocksToMarkdown(\n callout_children_object\n );\n\n callout_string += `${parsedData}\\n`;\n callout_children.map((child) => {\n callout_string += `${child.parent}\\n\\n`;\n });\n\n parsedData = md.callout(callout_string.trim(), block[type].icon);\n }\n break;\n\n case \"bulleted_list_item\":\n {\n parsedData = md.bullet(parsedData);\n }\n break;\n\n case \"numbered_list_item\":\n {\n parsedData = md.bullet(parsedData, block.numbered_list_item.number);\n }\n break;\n\n case \"to_do\":\n {\n parsedData = md.todo(parsedData, block.to_do.checked);\n }\n break;\n }\n\n return parsedData;\n }\n\n /**\n * Annoate text using provided annotations\n * @param {string} text - String to be annotated\n * @param {Annotations} annotations - Annotation object of a notion block\n * @returns {string} - Annotated text\n */\n annotatePlainText(text: string, annotations: Annotations): string {\n // if text is all spaces, don't annotate\n if (text.match(/^\\s*$/)) return text;\n\n const leadingSpaceMatch = text.match(/^(\\s*)/);\n const trailingSpaceMatch = text.match(/(\\s*)$/);\n\n const leading_space = leadingSpaceMatch ? leadingSpaceMatch[0] : \"\";\n const trailing_space = trailingSpaceMatch ? trailingSpaceMatch[0] : \"\";\n\n text = text.trim();\n\n if (text !== \"\") {\n if (annotations.code) text = md.inlineCode(text);\n if (annotations.bold) text = md.bold(text);\n if (annotations.italic) text = md.italic(text);\n if (annotations.strikethrough) text = md.strikethrough(text);\n if (annotations.underline) text = md.underline(text);\n }\n\n return leading_space + text + trailing_space;\n }\n}\n"]}
|
package/build/types/index.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ 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
|
-
saveChildPage?: boolean;
|
|
12
|
+
separateChildPage?: boolean;
|
|
14
13
|
};
|
|
15
14
|
export interface NotionToMarkdownOptions {
|
|
16
15
|
notionClient: Client;
|
|
17
16
|
config?: ConfigurationOptions;
|
|
18
17
|
}
|
|
18
|
+
export type MdStringObject = Record<string, string>;
|
|
19
19
|
export type MdBlock = {
|
|
20
20
|
type?: string;
|
|
21
21
|
blockId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,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;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,MAAM,oBAAoB,GAAG;IACjC,
|
|
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;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,MAAM,oBAAoB,GAAG;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AACF,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,oBAAoB,C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AC;QACrB,SAAS,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,SAAS,CAAC;KAClB,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;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};\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notion-to-md",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.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,6 @@
|
|
|
47
46
|
"typescript": "^4.5.4"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"fs-extra": "^11.1.1",
|
|
51
49
|
"markdown-table": "^2.0.0"
|
|
52
50
|
}
|
|
53
51
|
}
|
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"]}
|