GithubHelp home page GithubHelp logo

tryfabric / martian Goto Github PK

View Code? Open in Web Editor NEW
293.0 7.0 40.0 596 KB

Markdown to Notion: Convert Markdown and GitHub Flavoured Markdown to Notion API Blocks and RichText πŸ”€πŸ“

Home Page: https://www.npmjs.com/package/@tryfabric/martian

License: MIT License

JavaScript 0.13% TypeScript 99.87%
notion markdown gfm ast fabric

martian's People

Contributors

bats64mgutsi avatar cliftonc avatar dependabot[bot] avatar elioby avatar endbug avatar marissamarym avatar rr-codes avatar shelltr avatar vaayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

martian's Issues

bug: markdownToRichText not working if there are multiple new lines

Discuss in #public-issue-10--bug-markdowntorichtext-not-working-if-there-are-multiple-new-li

import { markdownToRichText } from "@instantish/martian";

const md = 'hello  \n  \n[sadsa](http://google.com)  \n  \n  \n  \n  \n**Bye**'
const rawRichTextArr = markdownToRichText(md);

error:

'Unsupported markdown element: {"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"hello","position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":1,"column":6,"offset":5}}}],"position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":1,"column":8,"offset":7}}},{"type":"paragraph","children":[{"type":"link","title":null,"url":"http://google.com","children":[{"type":"text","value":"sadsa","position":{"start":{"line":3,"column":2,"offset":12},"end":{"line":3,"column":7,"offset":17}}}],"position":{"start":{"line":3,"column":1,"offset":11},"end":{"line":3,"column":27,"offset":37}}}],"position":{"start":{"line":3,"column":1,"offset":11},"end":{"line":3,"column":29,"offset":39}}},{"type":"paragraph","children":[{"type":"strong","children":[{"type":"text","value":"Bye","position":{"start":{"line":8,"column":3,"offset":54},"end":{"line":8,"column":6,"offset":57}}}],"position":{"start":{"line":8,"column":1,"offset":52},"end":{"line":8,"column":8,"offset":59}}}],"position":{"start":{"line":8,"column":1,"offset":52},"end":{"line":8,"column":8,"offset":59}}}],"position":{"start":{"line":1,"column":1,"offset":0},"end":{"line":8,"column":8,"offset":59}}}'

Issue happens if there are more than one new lines.
another example where it would break:

const md = `
hello

bye

go
`;

expected output: it should convert to richText object preserving new lines

Bug: Notion rich_text[] max length is 100, markdownToBlocks() can create more than the limit

Hi, thanks for this package!

I noted in the documentation that it should automatically try and spread data that would be too long into multiple blocks, however after using markdownToBlocks() with some data that contained many lines and line breaks, the result was a paragraph block with a rich_text array that had over 100 items, which is over Notion's API limit for rich_text items.

When reading the docs, I thought it might try and spread the excess rich_text items into other blocks, but looking at the source code it will either truncate the array or leave it as it is - I think we should create X-amount of blocks until all excess rich_text items can fit?

table block not working

Hello, thanks for maintaining this tool. πŸ™

I am trying to create a basic table, but am unable to do so. My table looks like this:

| Date       | Exercise      |
|------------|---------------|
| 27.08.2022 | exercise 0    |
| 30.08.2022 | exercise 1    |
| 01.09.2022 | exercise 2    |
| 02.09.2022 | exercise 3    |

However the request fails with:

@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'body failed validation: body.children[21].table.table-width should be not present, instead was `5`.'
}
/**Path**/node_modules/@notionhq/client/build/src/errors.js:162
        return new APIResponseError({
               ^

APIResponseError: body failed validation: body.children[21].table.table-width should be not present, instead was `5`.

I am using markdownToBlocks function with package versions:

    "@notionhq/client": "2.2.0",
    "@tryfabric/martian": "1.2.4",

Anyone else facing similar issue?

Images should render as Image block instead of Paragraph block

Discuss in #issue-1--images-should-render-as-image-block-instead-of-paragraph-block

First of all thanks for making this library public. πŸ’œ

I am trying to convert markdown to Notion blocks. Everything works fine except images.

The images are currently rendered as a paragraph block

{
   "object":"block",
   "type":"paragraph",
   "paragraph":{
      "text":[
         {
            "type":"text",
            "annotations":{
               "bold":false,
               "strikethrough":false,
               "underline":false,
               "italic":false,
               "code":false,
               "color":"default"
            },
            "text":{
               "content":"https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/s_C6DD37D8ED67AB804309E3524813327121D8EA01ECCF02AF2243019807FF6CCA_1631271964338_notion-front-page-hero.png?resize=1000,716&ssl=1"
            }
         }
      ]
   }
},

They should be rendered like

{
   "object":"block",
   "type":"image",
   "image":{
      "type":"external",
      "external":{
         "url":"https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/s_C6DD37D8ED67AB804309E3524813327121D8EA01ECCF02AF2243019807FF6CCA_1631271964338_notion-front-page-hero.png?resize=1000,716&ssl=1"
      }
   }
},

Can you tell me how to do so?

Thanks

Undefined Error on parsing empty list items

Discuss in #issue-2--undefined-error-on-parsing-empty-list

First of all. thanks for making this open-source love the way it's helping us at @meetshepherd. πŸ™ŒπŸ»

Issue

If the markdown has an empty NumberedListItem or BulletedListItem parsing list to notion blocks fails.

This is what I mean by having an empty NumberedListItem or BulletedListItem πŸ‘‡πŸ»
(they have the formatting of a Bulleted/Number list with no text)

Empty BulletedListItem Empty NumberedListItem
image image

Error Screenshot

image

Rich Text Link URL value as "url"

We noticed recently that some text when converting through markdownToBlocks gets a bad URL value, with blocks that looks like:

[
  {
    "object": "block",
    "type": "paragraph",
    "paragraph": {
      "rich_text": [
        {
          "type": "text",
          "annotations": {
            "bold": false,
            "strikethrough": false,
            "underline": false,
            "italic": false,
            "code": false,
            "color": "default"
          },
          "text": {
            "content": "https://60f06c1c5a1772003b824d76-gclpzqfgft.chromatic.com/?path=/story/poi-map--create-point-poi",
            "link": {
              "type": "url",
              "url": "url" // <- this fails Notion client
            }
          }
        }
      ]
    }
  },
  // ...<other blocks>
]

Where the source is simply the link text https://60f06c1c5a1772003b824d76-gclpzqfgft.chromatic.com/?path=/story/poi-map--create-point-poi

This would trigger an error when creating the blocks on Notion:

@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'Content creation Failed. Fix the following: \n' +
    'Invalid URL for link.\n' +
    'Invalid URL for link.\n' +
    'Invalid URL for link.'
}

At the moment, we employ a patch mutation script to address this as the following:

const seekFixFalseURLs = (blocks) => { // mutates blocks
  blocks.forEach((block) => {
    ((block[block.type] || {}).rich_text || []).forEach((rt) => {
      if ((rt[rt.type].link || {}).url === 'url') {
        rt[rt.type].link.url = rt[rt.type].content
      }
    })
  })
}

Notion API throws an error concerning body.image.type

I'm facing this issue when I use the function markdownToBlocks.

@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'body failed validation: body.image.type should be not present, instead was `"external"`.'
}

Equation block and inline math support

Discuss in #public-issue-22--equation-block-and-inline-math-support

Thanks for the great package!

Martian seems not support math equations in markdown. For example:

Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following
equation.

$$
L = \frac{1}{2} \rho v^2 S C_L
$$

would be converted into plain text paragraph, keeping all $ and $$ symbols.

I found unified plugin remark-math may be useful. It would be amazing if Martian add support for math equations.

Paragraph text with multiple dollar amounts incorrectly creates an equation block.

Problem

Paragraph text with multiple dollar amounts incorrectly creates an equation block.

Working Example

markdownToBlock('A painting by John Doe sold for $9M at auction. A previous piece of his sold for $5M last year.');

Actual Result

Generated JSON block

[
  {
    "object": "block",
    "type": "paragraph",
    "paragraph": {
      "rich_text": [
        {
          "type": "text",
          "annotations": {
            "bold": false,
            "strikethrough": false,
            "underline": false,
            "italic": false,
            "code": false,
            "color": "default"
          },
          "text": {
            "content": "A painting by John Doe sold for "
          }
        },
        {
          "type": "equation",
          "annotations": {
            "bold": false,
            "strikethrough": false,
            "underline": false,
            "italic": false,
            "code": false,
            "color": "default"
          },
          "equation": {
            "expression": "9M at auction. A previous piece of his sold for "
          }
        },
        {
          "type": "text",
          "annotations": {
            "bold": false,
            "strikethrough": false,
            "underline": false,
            "italic": false,
            "code": false,
            "color": "default"
          },
          "text": {
            "content": "5M last year."
          }
        }
      ]
    }
  }
]

Screenshot when saved to Notion API
Screen Shot 2023-05-09 at 22 11 15

Expected Result

[
  {
    "object": "block",
    "type": "paragraph",
    "paragraph": {
      "rich_text": [
        {
          "type": "text",
          "annotations": {
            "bold": false,
            "strikethrough": false,
            "underline": false,
            "italic": false,
            "code": false,
            "color": "default"
          },
          "text": {
            "content": "A painting by John Doe sold for $9M at auction. A previous piece of his sold for $5M last year."
          }
        }
      ]
    }
  }
]

markdownToRichText ignores \n

I've noticed that markdownToRichText completely ignores new lines break both \n(both at the end and the beginning of a line) and double space(at the end of the line).
Is there a way to make these things work? I would love to have child text block be created for the newlines break because with without it, there is no indentation in the whole callout block

Nested number/bullet list combination ends up with error

Discuss in #public-issue-15--nested-numberbullet-list-combination-ends-up-with-error

I've a deeply nested list items in my .md file, like this:

1. **Something important**

    1. Sub step one
        - something to remember
        - parameters: 
          - param 1
          - param 2
          - param 3

This formats correctly in GH:

  1. Something important

    1. Sub step one
      • something to remember
      • parameters:
        • param 1
        • param 2
        • param 3

but when converted to blocks and pushed as children element in the Notion API call I get error:
'{"object":"error","status":400,"code":"validation_error","message":"body failed validation: body.children[1].numbered_list_item.children[0].numbered_list_item.children[0].numbered_list_item.children should be not present, instead was `[{\\"object\\":\\"block\\",\\"type\\":\\"bulleted_list_item\\",\\"bullete...`."}'.
I tried recreating that styling manually in Notion and it seems to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.