Skip to content

markdown within javascript #2132

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

You must be logged in to vote

The most idiomatic approach in MDX would be to have two MDX files.
A component file thing.mdx (which can also include props) and a page/document MDX file which imports thing.mdx and uses it as a component.
This approach is already supported today.

thing.mdx

# Hello {props.place}

document.mdx

import Thing from './thing.mdx'

<Thing place="world" />

The syntax you propose, is not something MDX core supports, nor do I think core should support it.
Not all JavaScript strings are MDX nor should they be interpreted as such.

Having a plain text strings is a valid use case, and a common one as well, for example:

export const frontmatter = { key: 'value' }

Trying to support string either as MDX o…

Replies: 2 comments 1 reply

Comment options

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

You must be logged in to vote
1 reply
@ChristianMurphy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants