@@ -37,9 +37,9 @@ A basic hello world:
37
37
``` jsx
38
38
import React from ' react'
39
39
import ReactMarkdown from ' react-markdown'
40
- import { render } from ' react-dom'
40
+ import ReactDom from ' react-dom'
41
41
42
- render (< ReactMarkdown> # Hello, * world* ! < / ReactMarkdown> , document .body )
42
+ ReactDom . render (< ReactMarkdown> # Hello, * world* ! < / ReactMarkdown> , document .body )
43
43
```
44
44
45
45
<details >
@@ -53,19 +53,22 @@ render(<ReactMarkdown># Hello, *world*!</ReactMarkdown>, document.body)
53
53
54
54
</details >
55
55
56
- Here is an example using ` require ` s, passing the markdown as a string, and how
56
+ Here is an example that shows passing the markdown as a string and how
57
57
to use a plugin ([ ` remark-gfm ` ] [ gfm ] , which adds support for strikethrough,
58
58
tables, tasklists and URLs directly):
59
59
60
60
``` jsx
61
- const React = require ( ' react' )
62
- const ReactMarkdown = require ( ' react-markdown ' )
63
- const render = require ( ' react-dom ' ). render
64
- const gfm = require ( ' remark-gfm' )
61
+ import React from ' react'
62
+ import ReactDom from ' react-dom '
63
+ import ReactMarkdown from ' react-markdown '
64
+ import remarkGfm from ' remark-gfm'
65
65
66
66
const markdown = ` Just a link: https://reactjs.com.`
67
67
68
- render (< ReactMarkdown remarkPlugins= {[gfm]} children= {markdown} / > , document .body )
68
+ ReactDom .render (
69
+ < ReactMarkdown children= {markdown} remarkPlugins= {[remarkGfm]} / > ,
70
+ document .body
71
+ )
69
72
```
70
73
71
74
<details >
@@ -144,8 +147,8 @@ strikethrough, tables, tasklists and URLs directly:
144
147
``` jsx
145
148
import React from ' react'
146
149
import ReactMarkdown from ' react-markdown'
147
- import { render } from ' react-dom'
148
- import gfm from ' remark-gfm'
150
+ import ReactDom from ' react-dom'
151
+ import remarkGfm from ' remark-gfm'
149
152
150
153
const markdown = ` A paragraph with *emphasis* and **strong importance**.
151
154
@@ -161,7 +164,10 @@ A table:
161
164
| - | - |
162
165
`
163
166
164
- render (< ReactMarkdown remarkPlugins= {[gfm]} children= {markdown} / > , document .body )
167
+ ReactDom .render (
168
+ < ReactMarkdown children= {markdown} remarkPlugins= {[remarkGfm]} / > ,
169
+ document .body
170
+ )
165
171
```
166
172
167
173
<details >
@@ -211,11 +217,11 @@ second.
211
217
``` jsx
212
218
import React from ' react'
213
219
import ReactMarkdown from ' react-markdown'
214
- import { render } from ' react-dom'
215
- import gfm from ' remark-gfm'
220
+ import ReactDom from ' react-dom'
221
+ import remarkGfm from ' remark-gfm'
216
222
217
- render (
218
- < ReactMarkdown remarkPlugins= {[[gfm , {singleTilde: false }]]}>
223
+ ReactDom . render (
224
+ < ReactMarkdown remarkPlugins= {[[remarkGfm , {singleTilde: false }]]}>
219
225
This ~ is not~ strikethrough, but ~~ this is~~ !
220
226
< / ReactMarkdown> ,
221
227
document .body
@@ -243,24 +249,10 @@ In this case, we apply syntax highlighting with the seriously super amazing
243
249
244
250
``` jsx
245
251
import React from ' react'
252
+ import ReactDom from ' react-dom'
246
253
import ReactMarkdown from ' react-markdown'
247
254
import {Prism as SyntaxHighlighter } from ' react-syntax-highlighter'
248
- /* Use `…/dist/cjs/…` if you’re not in ESM! */
249
255
import {dark } from ' react-syntax-highlighter/dist/esm/styles/prism'
250
- import {render } from ' react-dom'
251
-
252
- const components = {
253
- code ({node, inline, className, children, ... props}) {
254
- const match = / language-(\w + )/ .exec (className || ' ' )
255
- return ! inline && match ? (
256
- < SyntaxHighlighter style= {dark} language= {match[1 ]} PreTag= " div" children= {String (children).replace (/ \n $ / , ' ' )} {... props} / >
257
- ) : (
258
- < code className= {className} {... props}>
259
- {children}
260
- < / code>
261
- )
262
- }
263
- }
264
256
265
257
// Did you know you can use tildes instead of backticks for code in markdown? ✨
266
258
const markdown = ` Here is some JavaScript code:
@@ -270,7 +262,30 @@ console.log('It works!')
270
262
~~~
271
263
`
272
264
273
- render (< ReactMarkdown components= {components} children= {markdown} / > , document .body )
265
+ ReactDom .render (
266
+ < ReactMarkdown
267
+ children= {markdown}
268
+ components= {{
269
+ code ({node, inline, className, children, ... props}) {
270
+ const match = / language-(\w + )/ .exec (className || ' ' )
271
+ return ! inline && match ? (
272
+ < SyntaxHighlighter
273
+ children= {String (children).replace (/ \n $ / , ' ' )}
274
+ style= {dark}
275
+ language= {match[1 ]}
276
+ PreTag= " div"
277
+ {... props}
278
+ / >
279
+ ) : (
280
+ < code className= {className} {... props}>
281
+ {children}
282
+ < / code>
283
+ )
284
+ }
285
+ }}
286
+ / > ,
287
+ document .body
288
+ )
274
289
```
275
290
276
291
<details >
@@ -295,17 +310,18 @@ is used to support math in markdown, and a transform plugin
295
310
296
311
``` jsx
297
312
import React from ' react'
298
- import { render } from ' react-dom'
313
+ import ReactDom from ' react-dom'
299
314
import ReactMarkdown from ' react-markdown'
300
315
import remarkMath from ' remark-math'
301
316
import rehypeKatex from ' rehype-katex'
317
+
302
318
import ' katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you
303
319
304
- render (
320
+ ReactDom . render (
305
321
< ReactMarkdown
322
+ children= {` The lift coefficient ($C_L$) is a dimensionless coefficient.` }
306
323
remarkPlugins= {[remarkMath]}
307
324
rehypePlugins= {[rehypeKatex]}
308
- children= {` The lift coefficient ($C_L$) is a dimensionless coefficient.` }
309
325
/ > ,
310
326
document .body
311
327
)
@@ -374,17 +390,20 @@ can spare the bundle size (±60kb minzipped), then you can use
374
390
375
391
``` jsx
376
392
import React from ' react'
393
+ import ReactDom from ' react-dom'
377
394
import ReactMarkdown from ' react-markdown'
378
395
import rehypeRaw from ' rehype-raw'
379
- import {render } from ' react-dom'
380
396
381
397
const input = ` <div class="note">
382
398
383
399
Some *emphasis* and <strong>strong</strong>!
384
400
385
401
</div>`
386
402
387
- render (< ReactMarkdown rehypePlugins= {[rehypeRaw]} children= {input} / > , document .body )
403
+ ReactDom .render (
404
+ < ReactMarkdown rehypePlugins= {[rehypeRaw]} children= {input} / > ,
405
+ document .body
406
+ )
388
407
```
389
408
390
409
<details >
@@ -408,7 +427,7 @@ markdown!
408
427
You can also change the things that come from markdown:
409
428
410
429
``` js
411
- < Markdown
430
+ < ReactMarkdown
412
431
components= {{
413
432
// Map `h1` (`# heading`) to use `h2`s.
414
433
h1: ' h2' ,
0 commit comments