{"_id":"@dantehemerson/notion-to-md","name":"@dantehemerson/notion-to-md","dist-tags":{"latest":"2.5.3"},"versions":{"2.5.3":{"name":"@dantehemerson/notion-to-md","version":"2.5.3","engines":{"node":">=12"},"main":"./build","types":"./build/index.d.ts","scripts":{"prepare":"npm run build","build":"tsc","prebuild":"npm run clean","clean":"rm -rf ./build","test":"jest","test:watch":"jest -w"},"keywords":["notion","markdown","md","notion","notion-api","notion-to-md","notion2md"],"author":{"name":"Souvik Kar Mahapatra","email":"souvikat001+chitchat@gmail.com"},"license":"ISC","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/souvikinator/notion-to-md.git"},"bugs":{"url":"https://github.com/souvikinator/notion-to-md/issues"},"homepage":"https://github.com/souvikinator/notion-to-md#readme","description":"convert notion pages, block and list of blocks to markdown (supports nesting)","devDependencies":{"@notionhq/client":"^1.0.1","@types/jest":"^27.4.1","@types/markdown-table":"^2.0.0","jest":"^27.4.7","ts-jest":"^27.1.3","typescript":"^4.5.4"},"dependencies":{"markdown-table":"^2.0.0"},"gitHead":"d038a5fe3d69beea16974ef9f93047d92e39ddd0","_id":"@dantehemerson/notion-to-md@2.5.3","_nodeVersion":"14.17.6","_npmVersion":"7.24.2","dist":{"integrity":"sha512-nXcnKd/VgV06NRTv0XDgGA5JhGlK5bDFEtacZqy5fXvg3XoT+yDe0+45OhF41DraAMsbBrU99cJV8lSzmLIToA==","shasum":"ec832ab558b1425ca51cb3b30ddba54440cd9668","tarball":"https://registry.npmjs.org/@dantehemerson/notion-to-md/-/notion-to-md-2.5.3.tgz","fileCount":39,"unpackedSize":97158,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDzQu54ysII3MuFDVhIwO3skr/wDrJSGu150WWfhgPbYAIhAP/fAs9WtvUp3uBlGcoidXC0aP0C9xLxyCDo2rZFC006"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi3h63ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrZZw//XOHoRaXA29Waee5QYDQhT2XUKZW3LKOykQnCYLZYC9qpBKN4\r\nh/L9Hdj8dgzgQiw5PEuV0seYGLNCzai5O8mM6LPm8f8Qu5hPyRpBI34LlRNh\r\n3ceaJpvzoOO3o/EkhHgQedRR6vk9olr7r+kYgG47Ski0lEivn/dcaSdJvlAA\r\nZUuPvEfK0Hw1e82SSaFdoiCqN/F75tIzg1WN+6z8dDeBYBf6DfIrWkK3hfAs\r\ngwrkIIbjynP89UnXLcOAi9hCcdb8f3LQqIv+i0UmH59xxINfC0rRLSZuyiYz\r\ndNl4Ky4lPBt0LkOCMfWjV76EkhS4O0h+DVIS2X1uVIVM8cAsMj2zK3KouP0c\r\nRX6Ki55ku2fjuCYtYNc8wdFe8b6L9w6TmE3AxSOK49i6VVqZe9NsaLxkK9SH\r\nnF9Bt86j7qmzI/mbUuSSaNEuqQahfuZu7iU+IpZwcv20F4nwsEGet2jPKLzW\r\niS8csU5XUopkOuxBltsN5B3+QK/aEHW4+ARVSUZn2oaee/bhRCdOMNgj9G4x\r\ndIimqqTPwQur3iOkME6SlQLN9arv6Gt8Gw4XvbtAhT7TEq7OpJEC7Zf0ue4I\r\nnOrHOT94CZMm99IQqgf7B4vCoZ+qfcvS0z+pX5nv30ndBjhjKTSOz9ZTMnst\r\nVZRaCZsD4pauN63zN6PPAf7CPp0eJRNKtuU=\r\n=IiYa\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"dantehemerson","email":"dantehemerson@gmail.com"},"directories":{},"maintainers":[{"name":"dantehemerson","email":"dantehemerson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/notion-to-md_2.5.3_1658724023724_0.11642384088420021"},"_hasShrinkwrap":false}},"time":{"created":"2022-07-25T04:40:23.650Z","2.5.3":"2022-07-25T04:40:23.959Z","modified":"2022-07-25T04:40:24.099Z"},"maintainers":[{"name":"dantehemerson","email":"dantehemerson@gmail.com"}],"description":"convert notion pages, block and list of blocks to markdown (supports nesting)","homepage":"https://github.com/souvikinator/notion-to-md#readme","keywords":["notion","markdown","md","notion","notion-api","notion-to-md","notion2md"],"repository":{"type":"git","url":"git+https://github.com/souvikinator/notion-to-md.git"},"author":{"name":"Souvik Kar Mahapatra","email":"souvikat001+chitchat@gmail.com"},"bugs":{"url":"https://github.com/souvikinator/notion-to-md/issues"},"license":"ISC","readme":"<img src=\"https://imgur.com/WgXdz9r.png\" />\n\n> 💡 For better readability and detailed instructions headover to the [wiki](https://github.com/souvikinator/notion-to-md/wiki)\n\n# Notion to Markdown\n\nConvert notion pages, block and list of blocks to markdown (supports nesting) using **[notion-sdk-js](https://github.com/makenotion/notion-sdk-js)**\n\n> **Note:** Before getting started, create [an integration and find the token](https://www.notion.so/my-integrations).\n\n<a href=\"https://www.producthunt.com/posts/notion-to-md?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-notion&#0045;to&#0045;md\" target=\"_blank\"><img src=\"https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=351669&theme=light\" alt=\"notion&#0045;to&#0045;md - Programmatically&#0032;convert&#0032;notion&#0032;pages&#0032;to&#0032;markdown | Product Hunt\" style=\"width: 250px; height: 54px;\" width=\"250\" height=\"54\" /></a>\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O1AFCJR)\n\n## Todo\n\n- [x] heading\n- [x] images\n- [x] quotes\n- [x] links\n- [x] bullets\n- [x] todo\n- [x] inline code\n- [x] code block\n- [x] strikethrough, underline, bold, italic\n- [x] nested blocks\n- [x] embeds, bookmarks, videos, files (converted to links)\n- [x] Simple tables\n- [x] toggle \n- [x] divider\n- [x] equation block (converted to code blocks)\n- [x] convert returned markdown object to string (`toMarkdownString()`)\n- [x] typescript support\n- [x] add tests\n\n## Install\n\n```Bash\n$ npm install notion-to-md\n```\n\n## Usage\n\n> **Note:** Details on methods can be found in [API section](https://github.com/souvikinator/notion-to-md#api)\n\n### converting markdown objects to markdown string\n\nThis is how the notion page looks for this example:\n\n![Imgur](https://imgur.com/O6bKCmH.png)\n\n```js\nconst { Client } = require(\"@notionhq/client\");\nconst { NotionToMarkdown } = require(\"notion-to-md\");\n// or\n// import {NotionToMarkdown} from \"notion-to-md\";\n\nconst notion = new Client({\n  auth: \"your integration token\",\n});\n\n// passing notion client to the option\nconst n2m = new NotionToMarkdown({ notionClient: notion });\n\n(async () => {\n  const mdblocks = await n2m.pageToMarkdown(\"target_page_id\");\n  const mdString = n2m.toMarkdownString(mdblocks);\n\n  //writing to file\n  fs.writeFile(\"test.md\", mdString, (err) => {\n    console.log(err);\n  });\n})();\n```\n\n**Output:**\n\n![output](https://imgur.com/XrUYrZ0.png)\n\n### converting page to markdown object\n\nExample notion page:\n\n![Imgur](https://imgur.com/9iqRpBl.png)\n\n```js\nconst { Client } = require(\"@notionhq/client\");\nconst { NotionToMarkdown } = require(\"notion-to-md\");\n\nconst notion = new Client({\n  auth: \"your integration token\",\n});\n\n// passing notion client to the option\nconst n2m = new NotionToMarkdown({ notionClient: notion });\n\n(async () => {\n  // notice second argument, totalPage.\n  const x = await n2m.pageToMarkdown(\"target_page_id\", 2);\n  console.log(x);\n})();\n```\n\n**Output:**\n\n```json\n[\n  {\n    \"parent\": \"# heading 1\",\n    \"children\": []\n  },\n  {\n    \"parent\": \"- bullet 1\",\n    \"children\": [\n      {\n        \"parent\": \"- bullet 1.1\",\n        \"children\": []\n      },\n      {\n        \"parent\": \"- bullet 1.2\",\n        \"children\": []\n      }\n    ]\n  },\n  {\n    \"parent\": \"- bullet 2\",\n    \"children\": []\n  },\n  {\n    \"parent\": \"- [ ] check box 1\",\n    \"children\": [\n      {\n        \"parent\": \"- [x] check box 1.2\",\n        \"children\": []\n      },\n      {\n        \"parent\": \"- [ ] check box 1.3\",\n        \"children\": []\n      }\n    ]\n  },\n  {\n    \"parent\": \"- [ ] checkbox 2\",\n    \"children\": []\n  }\n]\n```\n\n### converting list of blocks to markdown object\n\nsame notion page as before\n\n```js\nconst { Client } = require(\"@notionhq/client\");\nconst { NotionToMarkdown } = require(\"notion-to-md\");\n\nconst notion = new Client({\n  auth: \"your integration token\",\n});\n\n// passing notion client to the option\nconst n2m = new NotionToMarkdown({ notionClient: notion });\n\n(async () => {\n  // get all blocks in the page\n  const { results } = await notion.blocks.children.list({\n    block_id,\n  });\n\n  //convert to markdown\n  const x = await n2m.blocksToMarkdown(results);\n  console.log(x);\n})();\n```\n\n**Output**: same as before\n\n### Converting a single block to markdown string\n\n- only takes a single notion block and returns corresponding markdown string\n- nesting is ignored\n- depends on @notionhq/client\n\n```js\nconst { NotionToMarkdown } = require(\"notion-to-md\");\n\n// passing notion client to the option\nconst n2m = new NotionToMarkdown({ notionClient: notion });\n\nconst result = n2m.blockToMarkdown(block);\nconsole.log(result);\n```\n\n**result**:\n\n```\n![image](https://media.giphy.com/media/Ju7l5y9osyymQ/giphy.gif)\n```\n\n## Custom Transformers\nYou can define your own custom transformer for a notion type, to parse and return your own string.\n`setCustomTransformer(type, func)` will overload the parsing for the giving type.\n\n```js\nconst { NotionToMarkdown } = require(\"notion-to-md\");\nconst n2m = new NotionToMarkdown({ notionClient: notion });\nn2m.setCustomTransformer('embed', async (block) => {\n  const {embed} = block as any;\n  if (!embed?.url) return '';\n  return `<figure>\n  <iframe src=\"${embed?.url}\"></iframe>\n  <figcaption>${await n2m.blockToMarkdown(embed?.caption)}</figcaption>\n</figure>`;\n});\nconst result = n2m.blockToMarkdown(block);\n// Result will now parse the `embed` type with your custom function. \n```\n**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.\n\n## Contribution\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\nPlease make sure to update tests as appropriate.\n\n## Contributers\n\n<a href=\"https://github.com/souvikinator/notion-to-md/graphs/contributors\">\n  <img src=\"https://contrib.rocks/image?repo=souvikinator/notion-to-md\" />\n</a>\n\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","readmeFilename":"README.md"}