`): use regular link syntax instead (`[http://localhost:3000](http://localhost:3000)`)
- HTML syntax (``): use JSX instead (`
`)
- Unescaped `{` and `<`: escape them with `\` instead (`\{` and `\<`)
:::danger Experimental CommonMark support
Docusaurus v3 makes it possible to opt-in for a less strict, standard [CommonMark](https://commonmark.org/) support with the following options:
- The `format: md` front matter
- The `.md` file extension combined with the `siteConfig.markdown.format: "detect"` configuration
This feature is **experimental** and currently has a few [limitations](https://github.com/facebook/docusaurus/issues/9092).
:::
## 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/). In order to use `raw-loader`, you first need to install it in your project:
```bash npm2yarn
npm install --save raw-loader
```
Now you can import code snippets from another file as it is:
{/* prettier-ignore */}
```jsx title="myMarkdownFile.mdx"
import CodeBlock from '@theme/CodeBlock';
import MyComponentSource from '!!raw-loader!./myComponent';
{MyComponentSource}
```
```mdx-code-block
import CodeBlock from '@theme/CodeBlock';
import MyComponentSource from '!!raw-loader!@site/src/pages/examples/_myComponent';
{MyComponentSource}
```
See [using code blocks in JSX](./markdown-features-code-blocks.mdx#usage-in-jsx) for more details of the `` component.
:::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 to interpolate the imported text here.
:::
:::warning
This feature is experimental and might be subject to breaking API 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.
By convention, using the **`_` filename prefix** will not create any doc page and means the Markdown file is a **"partial"**, to be imported by other files.
```md title="_markdown-partial-example.mdx"
Hello {props.name}
This is text some content from `_markdown-partial-example.mdx`.
```
{/* prettier-ignore */}
```jsx title="someOtherDoc.mdx"
import PartialExample from './_markdown-partial-example.mdx';
```
```mdx-code-block
import PartialExample from './_markdown-partial-example.mdx';
```
This way, you can reuse content among multiple pages and avoid duplicating materials.
## Available exports {#available-exports}
Within the MDX page, the following variables are available as globals:
- `frontMatter`: the front matter as a record of string keys and values;
- `toc`: the table of contents, as a tree of headings. See also [Inline TOC](./markdown-features-toc.mdx#inline-table-of-contents) for a more concrete use-case.
- `contentTitle`: the Markdown title, which is the first `h1` heading in the Markdown text. It's `undefined` if there isn't one (e.g. title specified in the front matter).
```jsx
import TOCInline from '@theme/TOCInline';
import CodeBlock from '@theme/CodeBlock';
The table of contents for this page, serialized:
{JSON.stringify(toc, null, 2)}
The front matter of this page:
{Object.entries(frontMatter).map(([key, value]) => - {key}: {value}
)}
The title of this page is: {contentTitle}
```
```mdx-code-block
import TOCInline from '@theme/TOCInline';
The table of contents for this page, serialized:
{JSON.stringify(toc, null, 2)}
The front matter of this page:
{Object.entries(frontMatter).map(([key, value]) => - {key}: {value}
)}
The title of this page is: {contentTitle}
```