code-hike / codehike

Build rich content websites with Markdown and React
https://codehike.org
MIT License
4.69k stars 142 forks source link

Useable with mdx-bundler #432

Open gurkerl83 opened 2 weeks ago

gurkerl83 commented 2 weeks ago

Hi. Congratulations on the release! I'm really excited to start using this new version of CodeHike.

I have a quick question regarding compatibility. It seems that CodeHike v1 is not fully compatible with mdx-bundler, particularly since mdx-bundler doesn’t support specifying recmaPlugins. Is that correct, or is there a workaround for this?

Thx!

pomber commented 2 weeks ago

thanks!

haven't tried it yet. adding recmaPlugins to mdx-bundler, if it's not supported yet, shouldn't be too hard

if you want you can start by opening an issue there, here are some similar issues for reference:

gurkerl83 commented 2 weeks ago

Hi,

I managed to get it working by creating my own version of mdx-bundler. However, I noticed something that might be worth mentioning in the README. When using tools like this, having jsx: true in the config section can lead to a general error, which many users may not immediately understand. It could be helpful to include a note in the documentation about this. The process works fine without setting jsx: true.

const mdxOptions = {
  remarkPlugins: [[remarkCodeHike, chConfig]],
  recmaPlugins: [[recmaCodeHike, chConfig]],
  jsx: true,
}

According to the documentation, jsx: true determines whether JSX is kept uncompiled:

jsx (boolean, default: false) — whether to keep JSX; the default is to compile JSX away so that the resulting file is immediately runnable.

What is the intended use case for keeping JSX uncompiled in CodeHike? Understanding the reasoning behind this option would be helpful.

@pomber is the jsx: true required for code blocks?

Thx!

pomber commented 2 weeks ago

I managed to get it working by creating my own version of mdx-bundler.

Nice, was it hard? do you think you can send a PR to the mdx-bundler repo?

What is the intended use case for keeping JSX uncompiled in CodeHike? is the jsx: true required for code blocks?

It's not required. jsx: false wasn't supported by Code Hike before, but now it should work the same as jsx: true.

Internally, the recmaCodeHike plugin works differently depending on that flag, and jsx: false is harder to transform. If you have a minimal example that works differently depending on the flag, please send it my way.