Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toMarkdownString has trouble with multiline blockquotes #117

Closed
captbaritone opened this issue Jan 4, 2025 · 4 comments
Closed

toMarkdownString has trouble with multiline blockquotes #117

captbaritone opened this issue Jan 4, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@captbaritone
Copy link

I'm using version 3.1.1 and it seems block quotes containing multiple paragraphs don't get serialized to markdown correctly with toMarkdownString.

mdBlocks

Here are the mdBlocks I get from Notion:

const mdBlocks = [
  {
    type: "paragraph",
    blockId: "c4222e16-b4a3-4f9d-a255-4a50c80656bf",
    parent: "One day at work I noticed a stray `}` at the bottom of a page of our product. I went searching for it, and found the culprit: during a refactor a `}` which had previously been used to enclose an expression within some JSX had been left behind. It occurred to me that this was likely a common error and something that could be linted for. I slapped together a quick rule that reported certain syntax characters that tend to get left behind (like `)`, `;`, `>`, `}` or `})`) as a lint error.\n\nI ran the rule on the code base and to my surprise there were a few _hundred_ examples of stray characters in our UI. A few weeks later a similar bug cropped up in a separate codebase at work where I had not enabled the rule. My colleague [Brad Zacher ](https://zacher.com.au/)remembered my lint rule and suggested it get added there as well. However, at that point an engineer on the [Flow](https://flow.org/) team suggested maybe Flow could just make some of these characters a syntax error. They did and uncovered and fixed a few hundred more errors.",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "0682d7d2-965e-4759-bfc5-06c5e5d901e4",
    parent: "",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "7886431a-098c-49e9-98ef-def13dcf5e9f",
    parent: "This inspired Brad and he decided to go on a mission to fix this not just at Meta, but in the whole ecosystem by opening pull requests on all the popular parsers. In all, some version of this fix has been added to:",
    children: [
    ],
  },
  {
    type: "bulleted_list_item",
    blockId: "8789baf2-2fa4-48a7-9dcf-619c2d759701",
    parent: "- [Flow](https://github.com/facebook/flow/commit/e1d0038042c2cba942ece36f96a0e1bd7fb138bd)",
    children: [
    ],
  },
  {
    type: "bulleted_list_item",
    blockId: "7385e04d-9562-4db8-b203-53c957663995",
    parent: "- [Babel](https://github.com/babel/babel/pull/11046)",
    children: [
    ],
  },
  {
    type: "bulleted_list_item",
    blockId: "f86a9e19-8450-4ff6-8b0a-f10e58dedf21",
    parent: "- [Acorn](https://github.com/acornjs/acorn-jsx/issues/106)",
    children: [
    ],
  },
  {
    type: "bulleted_list_item",
    blockId: "eb248840-f4f9-4544-a0ab-889baeb3a7d9",
    parent: "- [TypeScript](https://github.com/microsoft/TypeScript/pull/36636)",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "204a7036-0cd4-4f53-86c0-3cf0c224e243",
    parent: "",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "779694cd-ab72-46b9-9ae8-3aa358611445",
    parent: "Brad himself shared this anecdote in his words as part of the [TypeScript GitHub issue](https://github.com/microsoft/TypeScript/issues/36341#issuecomment-582514466):",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "2973cf1f-ca4e-45b7-a631-8de7ab0bb69d",
    parent: "",
    children: [
    ],
  },
  {
    type: "quote",
    blockId: "0adc110f-77f2-465c-a57a-9c1972055ae5",
    parent: "> Backstory for how this got implemented in flow:",
    children: [
      {
        type: "paragraph",
        blockId: "31001e24-dd79-4b66-b5c8-520fd4bc1c88",
        parent: "A dangling `}` was missed in code review, was shipped to production, and had a bug reported for it.",
        children: [
        ],
      },
      {
        type: "paragraph",
        blockId: "14bc61ac-e4bb-4880-9997-5db78f1fddf8",
        parent: "Annoyed, the engineer quietly wrote a very simple lint rule to catch this (it just checked for `}` at the start/end of a JSXText node). They shipped it, and manually fixed up a few hundred cases across the facebook codebase.",
        children: [
        ],
      },
      {
        type: "paragraph",
        blockId: "694662d6-90db-4a1e-ba87-502b71d3330b",
        parent: "A few weeks later someone just happened to ask if there was a lint rule they could use for the react native codebase. I mentioned that the lint rule could be synced across, and an engineer on the flow team chimed in saying that they should probably just make it a flow parser error because it's technically invalid JSX.",
        children: [
        ],
      },
      {
        type: "paragraph",
        blockId: "8fbf09b0-cea4-4043-84ae-cead45588b7a",
        parent: "Fast forward another few weeks and the change was released in flow, and the flow engineer manually fixed up the remaining few hundred errors.",
        children: [
        ],
      },
      {
        type: "quote",
        blockId: "9239ca32-8bd1-40f5-a319-38f1b723f5b2",
        parent: "> Is there a good reason we want all these implementations to break people?",
        children: [
        ],
      },
      {
        type: "paragraph",
        blockId: "2a30436d-2d54-424c-90c8-3b3f5e5be08a",
        parent: "This is a net benefit for everyone - it's very rare that a dangling `}` or `>` is intentional from what I've seen.",
        children: [
        ],
      },
      {
        type: "paragraph",
        blockId: "dd44533a-40d8-4e68-905c-e9da7f75c224",
        parent: "You can't include `<` or `{` in JSX text anyways, so this just bring parity in for `>` and `}`.",
        children: [
        ],
      },
    ],
  },
  {
    type: "paragraph",
    blockId: "f6563cf9-06b7-40db-a611-4aba65c595da",
    parent: "",
    children: [
    ],
  },
  {
    type: "paragraph",
    blockId: "3a00eeb6-aa23-421b-b9b5-3d6c3383a6ce",
    parent: "I’m so grateful for Brad’s initiative here which I am confident fixed many issues across the React ecosystem, sparing us as users from encountering these stray syntax characters in the products we use every day, and us as React developers from shipping these embarrassing bugs.",
    children: [
    ],
  },
]

Notion UI

Here's a screenshot of how that renders in Notion today

Screenshot 2025-01-04 at 3 03 04 PM

Current output markdown

https://gist.github.com/captbaritone/195e2e7d59a4fd1ea0661809bf735e71 (Put in a Gist to avoid escaping issues)

My current workaround

I've hacked around this for now with this patch.

Thanks

Thanks for the great library! It's been super helpful for using Notion as my CMS.

@souvikinator
Copy link
Owner

Thanks for reporting the issue! I'm glad you find the library useful. If you're open to it, a PR would be amazing :)
I’ll review and merge it quickly.

Appreciate the shoutout in your fantastic blog! A major v4 upgrade is in the works, addressing most of the points you mentioned. Your feedback or contributions to the [v4 proposal](#112) would be invaluable.

Meanwhile, I’m tackling smaller fixes before rolling everything else into v4. Thanks again! 😊

@souvikinator
Copy link
Owner

souvikinator commented Jan 5, 2025

@captbaritone Hey no worries I'll be fixing it today and will make a release asap, thank you

@souvikinator souvikinator added the bug Something isn't working label Jan 5, 2025
souvikinator added a commit that referenced this issue Jan 5, 2025
Signed-off-by: Souvik Kar Mahapatra <[email protected]>
@souvikinator
Copy link
Owner

Hi this has been fixed. Thank you for your contribution, if this continues to exist please feel free to reopen the issue.

@captbaritone
Copy link
Author

Thanks for the quick fix! I've validated that the issue I was hitting is now resolved!

captbaritone added a commit to captbaritone/jordaneldredge.com that referenced this issue Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants