pomber / docusaurus-mdx-2

A Docusaurus theme to add support for MDX v2
docusaurus-mdx-2.vercel.app
28 stars 1 forks source link

Errors returned with Remark plugins #5

Closed evanorti closed 2 years ago

evanorti commented 2 years ago

I want to use the katex and math remark plugins for parsing formulas, but I am getting errors:

Could not parse expression with acorn: Unexpected character '@'

It seems this happens to other remark plugins as well, such as the admonitions plugin (as specified in this repo's readme). I'd also like to use the directives plugin for simpler syntax, but am running into the same issue.

Is there any workaround for this, so I can still use Code Hike and these plugins?

Thanks

pomber commented 2 years ago

I tried with remark-math and rehype-katex and I don't see any error: https://stackblitz.com/edit/github-hdma5n?file=docusaurus.config.js,docs%2Fintro.md&initialpath=docs/intro

Make sure the versions you are using work with mdx v2. If you are still having problems, post a stackblitz example and I'll take a look.

pomber commented 2 years ago

Also, make sure to escape any opening braces { that aren't part of expressions. See here: https://mdxjs.com/docs/troubleshooting-mdx/#could-not-parse-expression-with-acorn-error

evanorti commented 2 years ago

@pomber Interesting, on my setup your example is showing that equations still aren't being parsed into katex.

I'll try some things and then post a stackblitz example.

Screen Shot 2022-08-05 at 10 14 02 AM

evanorti commented 2 years ago

Still can't get any of our other remark plugins are able to work either it seems.

Stackblitz here:

https://stackblitz.com/edit/tdocs?file=docusaurus.config.js

evanorti commented 2 years ago

Seems related to your comment here:

https://github.com/facebook/docusaurus/issues/4029#issuecomment-1098451055

evanorti commented 2 years ago

Using remark directives would also be helpful for us.

pomber commented 2 years ago

Seems related to your comment here:

facebook/docusaurus#4029 (comment)

Admonition doesn't work with mdx v2. Math and katex should work (according to the remark-math docs).

But I'm not familiar with those plugins. I don't see any error, and I don't know what's the expected output. It would help if you could provide an example with the correct output (maybe using another framework that support mdx v2, like nextjs).

evanorti commented 2 years ago

I found an example of what Katex math equations should look like using next.js mdx2, rehypeKatex and remarkMath:

https://codesandbox.io/s/next-mdx-math-katex-vd1qx?file=/package.json

Let me know if you need anything else.

pomber commented 2 years ago

I updated the plugins in your example

    "rehype-katex": "^6.0.2",
    "remark-math": "^5.1.1"

Looks like it works now https://stackblitz.com/edit/tdocs-vjasmd?file=docs%2Findex.mdx

image

evanorti commented 2 years ago

Awesome! Thank you for your help!