Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16ba1b9

Browse files
webinistaAisha Blake
and
Aisha Blake
authored
docs/glossary: Adds MDX entry. (gatsbyjs#21770)
* docs/glossary: Adds MDX entry. Also updates glossary.md, doc-links.yaml with links to MDX article. * Capitalize MDX * Prefer 'you' as the pronoun Co-authored-by: Aisha Blake <[email protected]>
1 parent 569fdb2 commit 16ba1b9

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

docs/docs/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Linting is the process of running a program that will analyze code for potential
206206

207207
## M
208208

209-
### MDX
209+
### [MDX](/docs/glossary/mdx/)
210210

211211
Extends [Markdown](#markdown) to support [React](#react) [components](#component) within your content.
212212

docs/docs/glossary/mdx.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: MDX
3+
disableTableOfContents: true
4+
---
5+
6+
Learn what MDX is, and how you can use it when creating content for your Gatsby site.
7+
8+
## What is MDX?
9+
10+
[MDX](/docs/glossary/#mdx) is an extension to [Markdown](/docs/glossary/markdown/) that lets you include [JSX](/docs/glossary/#jsx) in Markdown documents. MDX makes it possible to include React components in your Gatsby blog posts and pages.
11+
12+
Markdown defines a plain text syntax for HTML elements such as `h1`, `strong`, and `a`, but still supports inline HTML. An example Markdown document follows.
13+
14+
```markdown
15+
# Hello world!
16+
17+
You can use Markdown to create documents for [Gatsby](https://www.gatsbyjs.org/).
18+
19+
<figure class="chart">
20+
<object data="chart.svg" type="image/svg+xml"></object>
21+
<figcaption>MDX adoption has increased 120% since last year.</figcaption>
22+
</figure>
23+
```
24+
25+
MDX takes this one step further, and makes it possible to use JSX in your Markdown documents. Try making the `figure` element into a `Figure` component.
26+
27+
```jsx
28+
export const Figure = props => {
29+
return (
30+
<figure class="chart">
31+
<object data={props.data} type="image/svg+xml"></object>
32+
<figcaption>{props.caption}</figcaption>
33+
</figure>
34+
)
35+
}
36+
```
37+
38+
Now you can import this component into your Markdown document.
39+
40+
```markdown
41+
import { Figure } from './components/Figure';
42+
43+
# Hello world!
44+
45+
You can use Markdown to create documents for [Gatsby](https://www.gatsbyjs.org/).
46+
47+
<Figure data="chart.svg" caption="MDX adoption has increased 120% since last year." />
48+
```
49+
50+
If you're creating a Gatsby site from scratch, the [gatsby-starter-mdx-basic](https://github.com/ChristopherBiscardi/gatsby-starter-mdx-basic) is the fastest way to add MDX support. Use the Gatsby [CLI](/docs/glossary/#cli) to create a new project with this starter as a base.
51+
52+
```shell
53+
gatsby new my-mdx-starter https://github.com/ChristopherBiscardi/gatsby-starter-mdx-basic
54+
```
55+
56+
To use MDX with an existing Gatsby site, add the [`gatsby-plugin-mdx`](/packages/gatsby-plugin-mdx/?=gatsby-plugin-mdx) plugin. As with Gatsby itself, you can install it using [npm](/docs/glossary/#npm). You'll also need to install MDX itself, and the React implementation of MDX.
57+
58+
```shell
59+
npm install --save gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react
60+
```
61+
62+
Then add `gatsby-plugin-mdx` to your plugins list in `gatsby-config.js`, and set the [configuration options](/packages/gatsby-plugin-mdx/?=gatsby-plugin-mdx#configuration) you prefer.
63+
64+
MDX enhances Markdown's capabilities so that you can use React components anywhere in your Gatsby-powered site.
65+
66+
### Learn more about MDX
67+
68+
- [MDX](https://mdxjs.com/) official site
69+
- [What is MDX](https://www.youtube.com/watch?v=d2sQiI5NFAM) (video)
70+
- [Adding Components to Markdown with MDX](/docs/mdx/) from the Gatsby docs
71+
- [Introducing JSX](https://reactjs.org/docs/introducing-jsx.html) from the React documentation

www/src/data/sidebars/doc-links.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@
752752
link: /docs/glossary/jamstack
753753
- title: Markdown
754754
link: /docs/glossary/markdown/
755+
- title: MDX
756+
link: /docs/glossary/mdx
755757
- title: Node.js
756758
link: /docs/glossary/node
757759
- title: React

0 commit comments

Comments
 (0)