zhouzi / docusaurus-graphql-plugin

Docusaurus plugin generating Markdown documentation from a GraphQL schema.
https://gabinaureche.com/docusaurus-graphql-plugin/
23 stars 9 forks source link

Escape curly braces in code blocks #10

Closed Nickforall closed 1 year ago

Nickforall commented 2 years ago

Curly braces in code blocks gave some issues with mdx, this PR adds a replace for code and codespan tokens similar to the one used for text tokens.

zhouzi commented 2 years ago

Thanks for reporting and contributing @Nickforall 🙏 I added some tests to be sure that everything is working as expected. While doing so, I noticed two things:

  1. Some descriptions' markdown were not parsed so I added that where it was missing.
  2. Escaping curly braces in code blocks results in the ampersand being escape as well. So instead of { we end up with { (can be seen in the tests I added). Not sure why that's happening yet and if it's an issue. Do you have any idea? I'd appreciate your help with that, otherwise I'll look into it 🙂
zhouzi commented 2 years ago

Actually I reverted my commit because I am not sure to clearly identify the needs here. @Nickforall could you share a GraphQL snippet reproducing the bug? 🙏

Nickforall commented 2 years ago

This part of my schema broke for me:

type Address {
  """
  ENS profile which was used to refer to this address in a top-level argument, null if this address was queried as a hex address instead of an ENS name.

  *Example:*
  `address(name: "vitalik.eth") { profile { name } }` will return vitalik.eth as the profile's name.
  """
  profile: Profile
}

With the following error when building docs:

image
Nickforall commented 2 years ago

You may want to replace the other lbrace with the &# notation as well. That fixed some issues for me. It's likely docusaurus' markdown compiler not recognizing lbrace/rbrace and trying to escape it.

zhouzi commented 1 year ago

Thanks @Nickforall for the insights! I've been looking into this and turns out the Markdown parser this library uses (marked) escapes the content of the code blocks. I have removed that from the PR for now as it's not working and created #11 so we can look into it separately.

I'm merging this PR and will publish a new release with this fix 🙏

UPDATE: now released with 8.1.0.