Skip to content

Commit 7de6b87

Browse files
authored
Notion markdown addition (#16194)
* add notion-to-md package * Adding markdown page retrieval * Description and clarity updates
1 parent 01e0c2c commit 7de6b87

File tree

5 files changed

+96
-199
lines changed

5 files changed

+96
-199
lines changed

components/notion/actions/retrieve-block/retrieve-block.mjs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import notion from "../../notion.app.mjs";
22

33
export default {
44
key: "notion-retrieve-block",
5-
name: "Retrieve Block",
6-
description: "Get details of a block, which can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)",
7-
version: "0.0.6",
5+
name: "Retrieve Page Content",
6+
description: "Get page content as block objects or markdown. Blocks can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)",
7+
version: "0.1.0",
88
type: "action",
99
props: {
1010
notion,
@@ -13,18 +13,28 @@ export default {
1313
notion,
1414
"pageId",
1515
],
16-
label: "Block ID",
17-
description: "Select a block or provide a block ID",
1816
},
1917
retrieveChildren: {
2018
type: "boolean",
21-
label: "Retrieve Children",
22-
description: "Retrieve all the children (recursively) for the specified block. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information",
19+
label: "Retrieve Content (Child Blocks)",
20+
description: "Retrieve all the children (recursively) for the specified page. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information",
2321
optional: true,
2422
default: false,
2523
},
24+
retrieveMarkdown: {
25+
type: "boolean",
26+
label: "Retrieve as Markdown",
27+
description: "Return the page content as markdown instead of block objects.",
28+
optional: true,
29+
},
2630
},
2731
async run({ $ }) {
32+
if (this.retrieveMarkdown) {
33+
const response = await this.notion.getPageAsMarkdown(this.blockId);
34+
$.export("$summary", "Successfully retrieved page as markdown");
35+
return response;
36+
}
37+
2838
const block = await this.notion.retrieveBlock(this.blockId);
2939
if (this.retrieveChildren) {
3040
block.children = await this.notion.retrieveBlockChildren(block);

components/notion/actions/retrieve-page/retrieve-page.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import notion from "../../notion.app.mjs";
22

33
export default {
44
key: "notion-retrieve-page",
5-
name: "Retrieve Page",
5+
name: "Retrieve Page Metadata",
66
description: "Get details of a page. [See the documentation](https://developers.notion.com/reference/retrieve-a-page)",
7-
version: "0.0.6",
7+
version: "0.0.7",
88
type: "action",
99
props: {
1010
notion,
11+
infoLabel: {
12+
type: "alert",
13+
alertType: "info",
14+
content: "If you need to retrieve page content or block objects, use the **Retrieve Page Content** action instead.",
15+
},
1116
pageId: {
1217
propDefinition: [
1318
notion,

components/notion/notion.app.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import notion from "@notionhq/client";
22
import NOTION_META from "./common/notion-meta-selection.mjs";
33
import { ConfigurationError } from "@pipedream/platform";
4+
import { NotionConverter } from "notion-to-md";
5+
import { DefaultExporter } from "notion-to-md/plugins/exporter";
46

57
export default {
68
type: "app",
@@ -355,5 +357,19 @@ export default {
355357

356358
return response.results;
357359
},
360+
async getPageAsMarkdown(pageId) {
361+
const client = this._getNotionClient();
362+
363+
const buffer = {};
364+
const exporter = new DefaultExporter({
365+
outputType: "buffer",
366+
buffer,
367+
});
368+
369+
const n2m = new NotionConverter(client).withExporter(exporter);
370+
await n2m.convert(pageId);
371+
372+
return Object.values(buffer)[0];
373+
},
358374
},
359375
};

components/notion/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [
@@ -13,7 +13,8 @@
1313
"@notionhq/client": "^2.2.3",
1414
"@pipedream/platform": "^3.0.3",
1515
"@tryfabric/martian": "^1.2.4",
16-
"lodash-es": "^4.17.21"
16+
"lodash-es": "^4.17.21",
17+
"notion-to-md": "^4.0.0-alpha.4"
1718
},
1819
"publishConfig": {
1920
"access": "public"

0 commit comments

Comments
 (0)