diff --git a/website/docs/guides/markdown-features/markdown-features-react.mdx b/website/docs/guides/markdown-features/markdown-features-react.mdx index 288f3cdb3dfa..b4b89129689e 100644 --- a/website/docs/guides/markdown-features/markdown-features-react.mdx +++ b/website/docs/guides/markdown-features/markdown-features-react.mdx @@ -72,6 +72,40 @@ Since all doc files are parsed using MDX, any HTML is treated as JSX. Therefore, ::: +## Importing code snippets {#importing-code-snippets} + +You can not only import a file containing a component definition, but also import any code file as raw text, and then insert it in a code block, thanks to [Webpack raw-loader](https://webpack.js.org/loaders/raw-loader/). + +```jsx title="myMarkdownFile.mdx" +import CodeBlock from '@theme/CodeBlock'; +import MyComponentSource from '!!raw-loader!./myComponent'; + +{MyComponentSource}; +``` + +import CodeBlock from '@theme/CodeBlock'; +import MyComponentSource from '!!raw-loader!@site/src/pages/examples/_myComponent'; + + + +{MyComponentSource} + + + +
+ +:::note + +You have to use `` rather than the Markdown triple-backtick ` ``` `, because the latter will ship out any of its content as-is, but you want JSX to insert the imported text here. + +::: + +:::warning + +This feature is experimental and might be subject to API breaking changes in the future. + +::: + ## Importing Markdown {#importing-markdown} You can use Markdown files as components and import them elsewhere, either in Markdown files or in React pages. Below we are importing from [another file](./markdown-features-intro.mdx) and inserting it as a component. @@ -82,10 +116,10 @@ import Intro from './markdown-features-intro.mdx'; ; ``` - - import Intro from './markdown-features-intro.mdx'; + +