Have you read the Contributing Guidelines on issues?
Prerequisites
Description
As per https://docusaurus.io/docs/markdown-features/react, I'm trying to import and .mdx file into another .mdx file, and have the host .mdx pass props to the one that its importing. Here's the syntax, from the page to which I just linked
_markdown-partial-example.mdx
<span>Hello {props.name}</span>
This is text some content from _markdown-partial-example.mdx
import PartialExample from './_markdown-partial-example.mdx';
<PartialExample name="Sebastien" />;
I can get it to insert the variable text but if only I insert at the start of a paragraph of markdown, or preferably, on a line all of its own.
Steps to reproduce
Code example, extended from new.docusaurus.io, is here: https://codesandbox.io/s/infallible-davinci-276im
When then example renders:
- click on the Docusaurus Tutorial button
- navigate to Tutorial Intro -> create-a-document page
- Scroll down to the Props variables testing section
This will show you how and when the prop variable renders.
The file docs/tutorial-basics/create-a-document.md is the one that imports the shared doc and passes in the myVariable prop to it. The file is just a few lines.
The file docs/shared-docs-test/_create-a-document.mdx is the file that is imported and which as the props passed to it.
Expected behaviour
We should be able to do a prop variable anywhere within the text of an imported .mdx file. It should render its value, and without messing up any surrounding formatting.
It seems to work okay in standalone .mdx, i.e. no docusaurus, see https://codesandbox.io/s/peaceful-bogdan-fceb9
Actual behaviour
A <>{props.name}<> doesn't work at all if its intermingled with other text before and after it. It only works at the start of a paragraph, although subsequent insertions within that paragraph will also work as long the paragraph starts off with another insertion. If the insertion is only in the middle of the paragraph somewhere, then you will see the underlying code instead of the rendered text.
Even when it does work, it messes up markdown elsewhere in the same paragraph, e.g. any markdown links will not get rendered to HTML anchors tags under the covers. Also, it will lose the paragraphs at the end, which I worked around by hard-coding <br /> tags.
Your environment
- Public source code: https://codesandbox.io/s/infallible-davinci-276im
- Public site URL: https://codesandbox.io/s/infallible-davinci-276im
- Docusaurus version used: Tested against main branch of main repo, cloned on 9 Dec 2021 when testing locally.
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 96.0.4664.45 (also latest Firefox). Node 14.18.1. Also tested on Codebox extending template from new.docusaurus.io
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10, running WSL (Ubuntu 20.04.3 LTS)
Reproducible demo
https://codesandbox.io/s/infallible-davinci-276im
Self-service
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clearoryarn clearcommand.rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages.Description
As per https://docusaurus.io/docs/markdown-features/react, I'm trying to import and .mdx file into another .mdx file, and have the host .mdx pass props to the one that its importing. Here's the syntax, from the page to which I just linked
_markdown-partial-example.mdx
This is text some content from
_markdown-partial-example.mdxI can get it to insert the variable text but if only I insert at the start of a paragraph of markdown, or preferably, on a line all of its own.
Steps to reproduce
Code example, extended from new.docusaurus.io, is here: https://codesandbox.io/s/infallible-davinci-276im
When then example renders:
This will show you how and when the prop variable renders.
The file docs/tutorial-basics/create-a-document.md is the one that imports the shared doc and passes in the
myVariableprop to it. The file is just a few lines.The file docs/shared-docs-test/_create-a-document.mdx is the file that is imported and which as the props passed to it.
Expected behaviour
We should be able to do a prop variable anywhere within the text of an imported .mdx file. It should render its value, and without messing up any surrounding formatting.
It seems to work okay in standalone .mdx, i.e. no docusaurus, see https://codesandbox.io/s/peaceful-bogdan-fceb9
Actual behaviour
A
<>{props.name}<>doesn't work at all if its intermingled with other text before and after it. It only works at the start of a paragraph, although subsequent insertions within that paragraph will also work as long the paragraph starts off with another insertion. If the insertion is only in the middle of the paragraph somewhere, then you will see the underlying code instead of the rendered text.Even when it does work, it messes up markdown elsewhere in the same paragraph, e.g. any markdown links will not get rendered to HTML anchors tags under the covers. Also, it will lose the paragraphs at the end, which I worked around by hard-coding
<br />tags.Your environment
Reproducible demo
https://codesandbox.io/s/infallible-davinci-276im
Self-service