Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor docs to use createRoot #779

Closed
wants to merge 7 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 49 additions & 52 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ A basic hello world:

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'

const markdown = '# Hi, *Pluto*!'

ReactDom.render(<Markdown>{markdown}</Markdown>, document.body)
export default function App() {
return <Markdown>{markdown}</Markdown>
}
```

<details>
Expand All @@ -142,16 +143,14 @@ directly):

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

const markdown = `Just a link: www.nasa.gov.`

ReactDom.render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>,
document.body
)
export default function App(){
return <Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>
}
```

<details>
Expand Down Expand Up @@ -308,7 +307,6 @@ tables, tasklists and URLs directly:

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

Expand All @@ -326,10 +324,9 @@ A table:
| - | - |
`

ReactDom.render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>,
document.body
)
export default function App() {
return <Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>
}
```

<details>
Expand Down Expand Up @@ -379,18 +376,18 @@ strikethrough:

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

const markdown = 'This ~is not~ strikethrough, but ~~this is~~!'

ReactDom.render(
<Markdown remarkPlugins={[[remarkGfm, {singleTilde: false}]]}>
{markdown}
</Markdown>,
document.body
)
export default function App() {
return (
<Markdown remarkPlugins={[[remarkGfm, {singleTilde: false}]]}>
{markdown}
</Markdown>
)
}
```

<details>
Expand All @@ -416,7 +413,6 @@ In this case, we apply syntax highlighting with the seriously super amazing

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
import {dark} from 'react-syntax-highlighter/dist/esm/styles/prism'
Expand All @@ -429,29 +425,32 @@ console.log('It works!')
~~~
`

function generateCodeBlock(
props
) {
const match = /language-(\w+)/.exec(props.className || '');
return match ? (
<SyntaxHighlighter
style={dark}
language={match[1]}
showLineNumbers
className={props.className}
>
{String(props.children).replace(/\n$/, '')}
</SyntaxHighlighter>
) : (
<code className={props.className}>{props.children}</code>
);
}

ReactDom.render(
<Markdown
children={markdown}
components={{
code(props) {
const {children, className, node, ...rest} = props
const match = /language-(\w+)/.exec(className || '')
return match ? (
<SyntaxHighlighter
{...rest}
children={String(children).replace(/\n$/, '')}
style={dark}
language={match[1]}
PreTag="div"
/>
) : (
<code {...rest} className={className}>
{children}
</code>
)
}
components={{
code: generateCodeBlock,
}}
/>,
>
{children}
</Markdown>,
document.body
)
```
Expand All @@ -478,20 +477,20 @@ is used to support math in markdown, and a transform plugin

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import rehypeKatex from 'rehype-katex'
import remarkMath from 'remark-math'
import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you

const markdown = `The lift coefficient ($C_L$) is a dimensionless coefficient.`

ReactDom.render(
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
{markdown}
</Markdown>,
document.body
)
export default function App() {
return (
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
{markdown}
</Markdown>
)
}
```

<details>
Expand Down Expand Up @@ -602,7 +601,6 @@ can spare the bundle size (±60kb minzipped), then you can use

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import Markdown from 'react-markdown'
import rehypeRaw from 'rehype-raw'

Expand All @@ -612,10 +610,9 @@ Some *emphasis* and <strong>strong</strong>!

</div>`

ReactDom.render(
<Markdown rehypePlugins={[rehypeRaw]}>{markdown}</Markdown>,
document.body
)
export default function App() {
return <Markdown rehypePlugins={[rehypeRaw]}>{markdown}</Markdown>
}
```

<details>
Expand Down