This package has been deprecated

Author message:

WARNING: This project has been renamed to nast-util-from-notionapi. Install using nast-util-from-notionapi instead.

notionast-util-from-notionapi

0.3.1 • Public • Published

notionast-util-from-notionapi

An util that help users operate their notionapi-agent and convert a Notion page to a Notion Abstract Syntax Tree (NotionAST).

The library is currently a Work In Progress, so it may be unstable.

The library is unofficial.

Documentation

Usage

This is a Node.js module. You can install in your project.

npm i notionast-util-from-notionapi --save

You also need notionapi-agent.

npm i notionapi-agent --save

The agent is used to retrieve raw data from Notion's API /api/v3/getRecordValues.

Quickstart

const fs = require('fs')

const NotionAgent = require('notionapi-agent')
const downloadPageAsTree = require('notionast-util-from-notionapi')

/* Fill in your token. */
const options = {
  token: ''
}
const agent = new NotionAgent(options)

async function main() {
  try {
    /* Fill in a page ID. */
    let pageID = ''
    let tree = await downloadPageAsTree(pageID, agent)
    let file = `PageTree-${pageID}.json`
    fs.writeFileSync(file, JSON.stringify(tree), { encoding: 'utf-8' })
  } catch (error) {
    console.error(error)
  }
}

main()

API Methods

async downloadPageAsTree(pageID, agent)

Download a Notion page as a Notion Abstract Syntax Tree with a Notion API agent.

  • pageID - (required) The ID of a Notion page. Must be the one with dashes. e.g.

    'cbf2b645-xxxx-xxxx-xxxx-xxxxe8cfed93'
  • agent - (required) An API agent with method getRecordValues. I recomment using notionapi-agent.

Returns :

A Notion Abstract Syntax Tree. Refer to src/types/api-lagacy.ts for details.

interface BlockNode {
  id: string
  type: string
  data?: BlockProperties
  raw_value: BlockValue
  children: BlockNode[]
}

Notes

  • Notion has somewhat messed up with their data structure recently. BlockNode.raw_value.parent_id is incorrect for some blocks.

Readme

Keywords

Package Sidebar

Install

npm i notionast-util-from-notionapi

Weekly Downloads

6

Version

0.3.1

License

MIT

Unpacked Size

57.6 kB

Total Files

17

Last publish

Collaborators

  • dragonman225