-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolate variables in the MDX #5700
Comments
MDX can already use variables in content: import the data and render it with a JSX node: # title
some text
import data from "@site/static/data.json"
<span>Some data: {data.myData}</span> The only thing we propose in the referenced issue is to configure globally the "mdx scope" so that the If you want to use this data inside a md code block, it's a different story You'd have to use some # title
some text
import data from "@site/static/data.json"
<code>{`const data = "${data.myData}"}</code> Now, if you want to add a custom syntax for placeholders/variables to reduce verbosity and simplify usage, the way to go is to build your own Remark plugin to pre-process the markdown docs and replace placeholders/variables with your values (provided as plugin options) The Remark ecosystem may already have such a plugin, but I couldn't find a good one. Maybe try this one: https://github.com/mrzmmr/remark-variables If someone wants to build such a Remark plugin, I'd be happy to provide support and eventually add it to Docusaurus core if it makes sense. In my opinion, it must be a generic Remark plugin (that other frameworks could use as well) and it should not be developed and battle-tested in Docusaurus core. Technically, you can pass remark plugins as plugin options, and Docusaurus isn't blocking you from implementing this feature yourself. |
For variables in code blocks, see here: mdx-js/mdx#1095 (comment) |
@slorber do you have a code example of that remark plugin to substitute the placeholder in MD files? |
No official example I actually tried to share but I guess this could be an example: (just found this with Google) |
@slorber thanks a lot, you save my day! |
Thank you all for Docusaurus, it's really easy and understandable 🙌
💥 Proposal
Following the #395 (comment)
we are really need ability to interpolate variables in MDX markup of *.md files.
For example:
The text was updated successfully, but these errors were encountered: