How to Render Raw HTML with Inline Styles in MDX? #2609
-
Hi everyone, I'm currently facing an issue with MDX where I'm trying to render raw HTML that includes the style attribute, but it's throwing an error:
Here’s a simplified example of what I'm trying to do:
The issue arises with the style attribute inside the raw HTML. Has anyone faced this issue and found a workaround or solution? Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
MDX doesn’t support raw HTML. It supports JSX. What are you using MDX for? The most common use case is to use it with React. Are you using something else that accepts the |
Beta Was this translation helpful? Give feedback.
-
@remcohaszing thanks for the information. |
Beta Was this translation helpful? Give feedback.
The MDX compiler supports 2 languages: markdown and MDX.
The markdown language supports inline HTML. You can use
rehype-raw
to interpret this. Thestyle
attribute is a string. MDX compiles this to a prop with an object value when it compiles the markdown to JSX.The MDX language supports JSX. The
style
prop is unprocessed.React expects the
style
prop to be an object. It throws the error you’re seeing when it receivesstyle
as a string. MDX has nothing to do with this.You can’t mix HTML and JSX. These syntaxes conflict with each other. Everything works as expected. There are no plans to change the current behaviour.