diff --git a/readme.md b/readme.md index ba21e6ce..c3fefa1e 100644 --- a/readme.md +++ b/readme.md @@ -37,9 +37,9 @@ A basic hello world: ```jsx import React from 'react' import ReactMarkdown from 'react-markdown' -import {render} from 'react-dom' +import ReactDom from 'react-dom' -render(# Hello, *world*!, document.body) +ReactDom.render(# Hello, *world*!, document.body) ```
@@ -53,19 +53,22 @@ render(# Hello, *world*!, document.body)
-Here is an example using `require`s, passing the markdown as a string, and how +Here is an example that shows passing the markdown as a string and how to use a plugin ([`remark-gfm`][gfm], which adds support for strikethrough, tables, tasklists and URLs directly): ```jsx -const React = require('react') -const ReactMarkdown = require('react-markdown') -const render = require('react-dom').render -const gfm = require('remark-gfm') +import React from 'react' +import ReactDom from 'react-dom' +import ReactMarkdown from 'react-markdown' +import remarkGfm from 'remark-gfm' const markdown = `Just a link: https://reactjs.com.` -render(, document.body) +ReactDom.render( + , + document.body +) ```
@@ -144,8 +147,8 @@ strikethrough, tables, tasklists and URLs directly: ```jsx import React from 'react' import ReactMarkdown from 'react-markdown' -import {render} from 'react-dom' -import gfm from 'remark-gfm' +import ReactDom from 'react-dom' +import remarkGfm from 'remark-gfm' const markdown = `A paragraph with *emphasis* and **strong importance**. @@ -161,7 +164,10 @@ A table: | - | - | ` -render(, document.body) +ReactDom.render( + , + document.body +) ```
@@ -211,11 +217,11 @@ second. ```jsx import React from 'react' import ReactMarkdown from 'react-markdown' -import {render} from 'react-dom' -import gfm from 'remark-gfm' +import ReactDom from 'react-dom' +import remarkGfm from 'remark-gfm' -render( - +ReactDom.render( + This ~is not~ strikethrough, but ~~this is~~! , document.body @@ -243,24 +249,10 @@ In this case, we apply syntax highlighting with the seriously super amazing ```jsx import React from 'react' +import ReactDom from 'react-dom' import ReactMarkdown from 'react-markdown' import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter' -/* Use `…/dist/cjs/…` if you’re not in ESM! */ import {dark} from 'react-syntax-highlighter/dist/esm/styles/prism' -import {render} from 'react-dom' - -const components = { - code({node, inline, className, children, ...props}) { - const match = /language-(\w+)/.exec(className || '') - return !inline && match ? ( - - ) : ( - - {children} - - ) - } -} // Did you know you can use tildes instead of backticks for code in markdown? ✨ const markdown = `Here is some JavaScript code: @@ -270,7 +262,30 @@ console.log('It works!') ~~~ ` -render(, document.body) +ReactDom.render( + + ) : ( + + {children} + + ) + } + }} + />, + document.body +) ```
@@ -295,17 +310,18 @@ is used to support math in markdown, and a transform plugin ```jsx import React from 'react' -import {render} from 'react-dom' +import ReactDom from 'react-dom' import ReactMarkdown from 'react-markdown' import remarkMath from 'remark-math' import rehypeKatex from 'rehype-katex' + import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you -render( +ReactDom.render( , document.body ) @@ -374,9 +390,9 @@ can spare the bundle size (±60kb minzipped), then you can use ```jsx import React from 'react' +import ReactDom from 'react-dom' import ReactMarkdown from 'react-markdown' import rehypeRaw from 'rehype-raw' -import {render} from 'react-dom' const input = `
@@ -384,7 +400,10 @@ Some *emphasis* and strong!
` -render(, document.body) +ReactDom.render( + , + document.body +) ```
@@ -408,7 +427,7 @@ markdown! You can also change the things that come from markdown: ```js -