docs(v2): require using JSX flavored style objects in mdx (#2257)

* docs(v2): require using JSX flavored style objects instead of style attributes in Docusaurus 2

* resolve discussions
This commit is contained in:
Wei Gao 2020-02-01 20:27:06 +08:00 committed by GitHub
parent de4a25c297
commit e224361cd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 4 deletions

View file

@ -128,7 +128,9 @@ image: https://i.imgur.com/mErPwqL.png
Docusaurus has built-in support for [MDX](https://mdxjs.com), which allows you to write JSX within your Markdown files and render them as React components.
**Note:** While both `.md` and `.mdx` files are parsed using MDX, some of the syntax are treated slightly differently. For the most accurate parsing and better editor support, we recommend using the `.mdx` extension for files containing MDX syntax. Let's rename the previous file to `greeting.mdx`
**Note 1:** While both `.md` and `.mdx` files are parsed using MDX, some of the syntax are treated slightly differently. For the most accurate parsing and better editor support, we recommend using the `.mdx` extension for files containing MDX syntax. Let's rename the previous file to `greeting.mdx`.
**Note 2:** Since all doc files are parsed using MDX, any HTML is treated as JSX. Therefore, if you need to inline-style a component, follow JSX flavor and provide style objects. This behavior is different from Docusaurus 1. See also [Migrating from v1 to v2](./migrating-from-v1-to-v2.md#convert-style-attributes-to-style-objects-in-mdx).
Try this block here:

View file

@ -664,3 +664,21 @@ website
│ ├── version-1.1.0-sidebars.json
│ └── version-1.0.0-sidebars.json
```
### Convert style attributes to style objects in MDX
Docusaurus 2 uses JSX for doc files. If you have any style attributes in your Docusaurus 1 docs, convert them to style objects, like this:
```diff
---
id: demo
title: Demo
---
## Section
hello world
- pre style="background: black">zzz</pre>
+ pre style={{background: 'black'}}>zzz</pre>
```