-
-
Notifications
You must be signed in to change notification settings - Fork 124
v3 API
config contains options for extended functionalities.
config:{
separateChildPage: boolean, // default: false
parseChildPages: boolean // default: true
}-
separateChildPage: enable to separate child page content from the parent page content -
parseChildPages: disable to ignore child pages during fetching and parsing
- takes the output of
pageToMarkdownorblocksToMarkdownas an argument - converts to markdown string of object
-
parentproperty contains the target page markdown string. - if
separateChildPageis enabled inconfigthen all the child pages content are added corresponding to their title in the same object.
for (separateChildPage=false):

output:

for (separateChildPage=true):


output:

- Uses
blocksToMarkdowninternally. -
id(pageid) as input and converts all the blocks in the page to corresponding markdown object -
totalPageis the retrieve block children request number i.epage_size Maximum = totalPage * 100.
Notion API allows to fetch up to 100 children on a page. Total page stands for the number of pages required to get all the child blocks on a page where each page contains <= 100 blocks.
The default value is null which means all the blocks of the page will be converted to markdown, so one can choose to not pass any value
as totalPage.
How to use
totalPagearg ?
if the number of blocks in a notion page is indefinite or the requirement is to convert the whole notion page to markdown, then no need to pass
totalPageas argument.if the requirement is to convert the first
100blocks of the page to markdown then usetotalPageas1.if the notion page contains
150blocks thentotalPageargument should be greater than or equal to2leading topageSize = 2 * 100and rendering all150blocks.
Example:
// converting whole page to markdown
const x = await n2m.pageToMarkdown("target_page_id");
//or
const y = await n2m.pageToMarkdown("target_page_id",null);
// converting first 100 blocks to markdown.
const z = await n2m.pageToMarkdown("target_page_id",1);-
blocks: array of notion blocks -
totalPage: the retrieve block children request number i.epage_size Maximum = totalPage * 100. - deals with nested blocks
- uses
blockToMarkdowninternally.
- Takes single notion block and converts to markdown string
- does not deal with nested notion blocks
- Refer docs to know more about notion blocks
You can define your own custom transformer for a notion type, to parse and return your own string.
setCustomTransformer(type, func) will overload the parsing for the giving type.
const { NotionToMarkdown } = require("notion-to-md");
const n2m = new NotionToMarkdown({ notionClient: notion });
n2m.setCustomTransformer('embed', async (block) => {
const {embed} = block as any;
if (!embed?.url) return '';
return `<figure>
<iframe src="${embed?.url}"></iframe>
<figcaption>${await n2m.blockToMarkdown(embed?.caption)}</figcaption>
</figure>`;
});
const result = n2m.blockToMarkdown(block);
// Result will now parse the `embed` type with your custom function. Note: Be aware that setCustomTransformer will take only the last function for the given type. You can't set two different transforms for the same type.