Skip to content

How to allow string style prop (instead of object) #2333

Closed Answered by ChristianMurphy
zachkirsch asked this question in Q&A
Discussion options

You must be logged in to vote

Welcome @zachkirsch! 👋
I assume you are using React?

MDX is Markdown and JSX.
When used with React, React only accepts style as an object.
I'd generally recommend sticking with React's convention.

That said, if you really want to change that behavior to accept a string.
You'd need to get into the parsing and abstract syntax tree internals.
I'd recommend starting by reading https://unifiedjs.com/learn/
Then playing around with https://mdxjs.com/playground/ to familiarize yourself with the 3 syntax trees MDX uses.

You could create a recma plugin to modify the esast (JavaScript) syntax tree.
Find the style attributes which are a string, and use a CSS parser to transform that text into a React

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by zachkirsch
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants