{"_id":"@aggarwaldev/martian","_rev":"1-51a7f0a4d326401f26e412df8bf6b3da","name":"@aggarwaldev/martian","dist-tags":{"latest":"1.2.0"},"versions":{"1.2.0":{"name":"@aggarwaldev/martian","version":"1.2.0","description":"Converts Markdown to Notion Blocks and RichText","repository":{"type":"git","url":"git+https://github.com/instantish/martian.git"},"main":"build/src/index.js","types":"build/src/index.d.ts","scripts":{"test":"jest","lint":"gts lint","clean":"gts clean","compile":"tsc","fix":"gts fix","prepare":"npm run compile","pretest":"npm run compile","posttest":"npm run lint"},"keywords":["markdown","notion","parser","gfm"],"engines":{"node":">=14"},"author":{"name":"Richard Robinson"},"contributors":[{"name":"Clifton Cunningham","email":"clifton.cunningham@gmail.com","url":"https://medium.com/@clifcunn"},{"name":"Dev Aggarwal","email":"contact@aggarwal.dev","url":"https://aggarwal.dev"}],"license":"ISC","dependencies":{"@notionhq/client":"^0.4.5","remark-gfm":"^1.0.0","remark-parse":"^9.0.0","unified":"^9.2.1"},"devDependencies":{"@types/jest":"^27","@types/node":"^15.12.4","gts":"^3.1.0","jest":"^27.0.4","ts-jest":"^27.0.3","ts-node":"^10.0.0","typescript":"^4.3.4"},"publishConfig":{"access":"public"},"gitHead":"82db567272ec25ca4dc82f95c730a540a144dd3c","bugs":{"url":"https://github.com/instantish/martian/issues"},"homepage":"https://github.com/instantish/martian#readme","_id":"@aggarwaldev/martian@1.2.0","_nodeVersion":"14.17.6","_npmVersion":"7.24.0","dist":{"integrity":"sha512-3ina+oFlwTm2EadrtOR2dNTHUXG/rujxLagvWrv3jorsoj0yErOamw2/6ee9gdU8VZ/VkvelurAoGV8I5H5Nwg==","shasum":"4afb0369129d58acdba28dfc74efc1439f82db1d","tarball":"https://registry.npmjs.org/@aggarwaldev/martian/-/martian-1.2.0.tgz","fileCount":55,"unpackedSize":140289,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhwxJMCRA9TVsSAnZWagAAD/sP/3E9w0Hh/QiXwnrjQrAQ\nexluZrSL4GqEHlbKsZ1LwTODoM+Ugcuxfajo8Lacz3g3fyPPJ/TLs7d7617G\nwRt7D918Q9dxbkEDDR67inChkSYIMTnlZYksMJT4oqzglKr5XzSwUs96Zsnw\nYN+Vfc/Ne1fniOlH5A4ju7zGnAoeH4LPcPc1xyupM9TIuu5b3RdtXnv5YSuq\nwm0yq3v+xa6+dASkU3OO9tRKqpNPS9rhsQfttLH1Bvu2L3NSecvOwqqA5Vgs\nFGQ0jUAa/RpQrUexKt5mbaQ28L+KLUFd3nwZo9DfD4PAg59qwEq2MQo0n+2d\n+t/m5su2PLL2RPLGlfk+7K4VM5EOhHKKS+nEVae2NbkThRaV8MyL7hh0fopl\nmI+pLisEVVJ1ZmKLet5p3SDA8YDqzcrRyBqkX+6Xbduh24BngbdyskdvZs2E\nDraTse5J99oNgaH4L5CarZIetrj6pRpsFiku/+eVJKH6XRHQjzm5nqPmrP2D\nwz6NITZbRA69Eh0JI/eZwXHuAm9JFJYFuw07gu5v5+FVp9XK/f6sXC6dGTh4\nsdDwfIhv/YL78i2kkhh4TqO3QW0Ex1GvMKY213K9WZCB3lP61+jEKDMn0U1m\nbkKXCapxyqIcLFO+V76B2NDCyBXl3qOZ1kMkAcoUw3VvpWnyCtm1f6crQARf\nssG+\r\n=mraR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDpp0r4c/RAEF3n4nhqQlWPex33cIdXckD+hWjR4lQPjAiEA9dlbymQH7XE1O0G7BiWojV1euzSgpI7weZEqQY9rE74="}]},"_npmUser":{"name":"aggarwaldev","email":"contact@aggarwal.dev"},"directories":{},"maintainers":[{"name":"aggarwaldev","email":"contact@aggarwal.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/martian_1.2.0_1640174155802_0.3765587162995465"},"_hasShrinkwrap":false}},"time":{"created":"2021-12-22T11:55:55.763Z","1.2.0":"2021-12-22T11:55:56.042Z","modified":"2022-04-04T11:56:58.877Z"},"maintainers":[{"name":"aggarwaldev","email":"contact@aggarwal.dev"}],"description":"Converts Markdown to Notion Blocks and RichText","homepage":"https://github.com/instantish/martian#readme","keywords":["markdown","notion","parser","gfm"],"repository":{"type":"git","url":"git+https://github.com/instantish/martian.git"},"contributors":[{"name":"Clifton Cunningham","email":"clifton.cunningham@gmail.com","url":"https://medium.com/@clifcunn"},{"name":"Dev Aggarwal","email":"contact@aggarwal.dev","url":"https://aggarwal.dev"}],"author":{"name":"Richard Robinson"},"bugs":{"url":"https://github.com/instantish/martian/issues"},"license":"ISC","readme":"# Martian: Markdown to Notion Parser\n\n> NOTE: Please use the new NPM package at [@tryfabric/martian](https://www.npmjs.com/package/@tryfabric/martian).\n\nConvert Markdown and GitHub Flavoured Markdown to Notion API Blocks and RichText.\n\n[![Node.js CI](https://github.com/instantish/martian/actions/workflows/ci.yml/badge.svg)](https://github.com/instantish/martian/actions/workflows/ci.yml)\n[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)\n\nMartian is a Markdown parser to convert any Markdown content to Notion API block or RichText objects. It\nuses [unified](https://github.com/unifiedjs/unified) to create a Markdown AST, then converts the AST into Notion\nobjects.\n\nDesigned to make using the Notion SDK and API easier.  Notion API version 0.4.5.\n\n### Supported Markdown Elements\n\n* All inline elements (italics, bold, strikethrough, inline code, hyperlinks)\n* Lists (ordered, unordered, checkboxes) - to any level of depth\n* All headers (header levels >= 3 are treated as header level 3)\n* Code blocks\n* Block quotes\n* Images\n  - Inline images are extracted from the paragraph and added afterwards (as these are not supported in notion)\n  - Image urls are validated, if they are not valid as per the Notion external spec, they will be inserted as text for you to fix manually\n  - Embed images are allowed on specific domains via options.embedUrls. These images are inserted as embed block.\n\n## Usage\n\n```ts\nimport {markdownToBlocks, markdownToRichText} from '@instantish/martian';\nimport type {RichText, Block} from '@notionhq/client/build/src/api-types';\n\nconst richText: RichText[] = markdownToRichText(`**Hello _world_**`);\n\n// [\n//   {\n//     \"type\": \"text\",\n//     \"annotations\": {\n//       \"bold\": true,\n//     },\n//     \"text\": {\n//       \"content\": \"Hello \"\n//     }\n//   },\n//   {\n//     \"type\": \"text\",\n//     \"annotations\": {\n//       \"bold\": true,\n//       \"italic\": true,\n//     },\n//     \"text\": {\n//       \"content\": \"world\"\n//     }\n//   }\n// ]\n\nconst options = { allowUnsupportedObjectType: false, strictImageUrls: true, embedUrls: ['googleusercontent.com'] };\nconst blocks: Block[] = markdownToBlocks(`\n## this is a _heading 2_\n\n* [x] todo list item\n`, options);\n\n// [\n//   {\n//     \"object\": \"block\",\n//     \"type\": \"heading_2\",\n//     \"heading_2\": {\n//       \"text\": [\n//         ...\n//         {\n//           \"type\": \"text\",\n//           \"annotations\": {\n//             \"italic\": true\n//           }\n//           \"text\": {\n//             \"content\": \"heading 2\"\n//           }\n//         },\n//       ]\n//     }\n//   },\n//   {\n//     \"object\": \"block\",\n//     \"type\": \"to_do\",\n//     \"to_do\": {\n//       \"text\": [\n//         {\n//           \"type\": \"text\",\n//           \"annotations\": {\n//           },\n//           \"text\": {\n//             \"content\": \"todo list item\"\n//           }\n//         }\n//       ],\n//       \"checked\": true\n//     }\n//   }\n// ]\n```\n\n### Images - Strict Mode\n\nBy default, Notion will reject the entire document if you add a block that has an image with an invalid URL (this is not that nice), so by default this will parse in 'Strict Mode' where the image url is parsed, and if not valid, the image is actually parsed as text and added to the document.\n\nIn some instances, for example, you are parsing markdown where the image references are local file paths, you may want to allow them to flow through, so that in your client code you can upload the images somewhere and then update the URL paths to point to them before loading into Notion.\n\nDefault (strict mode enabled):\n\n```ts\nconst options = { strictImageUrls: true };\nconst blocks: Block[] = markdownToBlocks(`\n![image-invalid](https://image.com/blah)\n`)\n//  {\n//     \"type\": \"text\",\n//     \"annotations\": {\n//       ...\n//     },\n//     \"text\": {\n//       \"content\": \"https://image.com/blah\"\n//     }\n//   }\n```\n\nStrict mode disabled: \n\n```ts\nconst options = { strictImageUrls: false };\nconst blocks: Block[] = markdownToBlocks(`\n![image-invalid](https://image.com/blah)\n`)\n//  {\n//     \"type\": \"image\",\n//     \"image\": {\n//       \"url\": \"https://image.com/blah\"\n//     }\n//   }\n```\n\n### Unsupported Markdown Elements\n\n*tables*: Tables can be imported in an [unsupported mode](https://developers.notion.com/reference/block) if you add a flag to the parser.\n\nFirst, the default mode - it ignores the tables:\n\n```ts\nconst options = { allowUnsupportedObjectType: false };\nconst blocks: Block[] = markdownToBlocks(`\n# Table\n\n| First Header  | Second Header |\n| ------------- | ------------- |\n| Content Cell  | Content Cell  |\n| Content Cell  | Content Cell  |\n`, options);\n\n// [\n//   {\n//     \"object\": \"block\",\n//     \"type\": \"heading_1\",\n//     \"heading_1\": {\n//       \"text\": [\n//         {\n//           \"type\": \"text\",\n//           \"annotations\": {\n//             \"bold\": false,\n//             \"strikethrough\": false,\n//             \"underline\": false,\n//             \"italic\": false,\n//             \"code\": false,\n//             \"color\": \"default\"\n//           },\n//           \"text\": {\n//             \"content\": \"Table\"\n//           }\n//         }\n//       ]\n//     }\n//   }\n// ]\n```\n\nNext, with unsupported flag = true (note the `annotations` have been removed from the returned object to make it easier to see what is going on):\n\n\n```ts\nconst options = { allowUnsupportedObjectType: true };\nconst blocks: Block[] = markdownToBlocks(`\n# Table\n\n| First Header  | Second Header |\n| ------------- | ------------- |\n| Content Cell  | Content Cell  |\n| Content Cell  | Content Cell  |\n`, options)\n\n [\n//   {\n//     \"object\": \"block\",\n//     \"type\": \"heading_1\",\n//     \"heading_1\": {\n//       \"text\": [\n//         {\n//           \"type\": \"text\",\n//           \"text\": {\n//             \"content\": \"Table\"\n//           }\n//         }\n//       ]\n//     }\n//   },\n//   {\n//     \"object\": \"unsupported\",\n//     \"type\": \"table\",\n//     \"table\": {\n//       \"children\": [\n//         {\n//           \"object\": \"unsupported\",\n//           \"type\": \"table_row\",\n//           \"table_row\": {\n//             \"children\": [\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"First Header\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               },\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"Second Header\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               }\n//             ]\n//           }\n//         },\n//         {\n//           \"object\": \"unsupported\",\n//           \"type\": \"table_row\",\n//           \"table_row\": {\n//             \"children\": [\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"Content Cell\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               },\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"Content Cell\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               }\n//             ]\n//           }\n//         },\n//         {\n//           \"object\": \"unsupported\",\n//           \"type\": \"table_row\",\n//           \"table_row\": {\n//             \"children\": [\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"Content Cell\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               },\n//               {\n//                 \"object\": \"unsupported\",\n//                 \"type\": \"table_cell\",\n//                 \"table_cell\": {\n//                   \"children\": [\n//                     {\n//                       \"type\": \"text\",\n//                       \"text\": {\n//                         \"content\": \"Content Cell\"\n//                       }\n//                     }\n//                   ]\n//                 }\n//               }\n//             ]\n//           }\n//         }\n//       ]\n//     }\n//   }\n// ]\n```\n\nNote that if you send this document to Notion with the current version of the API it *will* fail, but this allows you to pre-parse the blocks in your client library, and do something with the tables.  In one example, the tables are being parsed out of the blocks, databases being created, that are then linked back to the imported page:  https://github.com/infinitaslearning/notionater/blob/main/index.js#L81-L203\n\n---\n\nBuilt with 💙 by the team behind [Fabric](https://tryfabric.com).\n\n<img src=\"https://static.scarf.sh/a.png?x-pxid=79ae4e0a-7e48-4965-8a83-808c009aa47a\" />\n","readmeFilename":"README.md"}