frontarm / mdx-util

Utilities for working with MDX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support custom pragma

tauren opened this issue · comments

First of all, great project! I've been trying to get several other projects cobbled together to do something similar to what you've built and it looks like you might save me a bunch of time.

I would like to use this library in a project (via the webpack loader), but I depend on the Babel transform-react-jsx plugin with the { pragma: "h" } option. This means that JSX is compiled to h(...) instead of React.createElement(...). Note that specifying /** @pragma h */ at the top of a file does the same thing, but only for a single file.

Unfortunately, it looks like MDXC is hard-coded to use a pragma of createElement. It would really help if this value could be customized for all *.md files. Or possibly support the pragma comment within the front-matter of individual MD files.

This would open up your tool to being used with various other virtual DOM libraries that support JSX syntax, including React-clones such as Preact.

This sounds like a useful feature. A couple options for adding this would be:

  • reading a pragma line that is similar to the prop and import lines
  • adding a command line option / option for the loader

Any thoughts on the advantages/disadvantages of both approaches?

Ideally, both approaches would be supported, but which would be simplest and easiest to implement? I have a short timeline for my project, so I can work with whatever solution is available soonest. Which would take less work?

I've added this feature as the pragma command line and API option. You can also pass an option to mdx-loader.