diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 058387620e..5a81f0bf7c 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -12,9 +12,11 @@ "@mdx-js/react": "^1.0.20", "classnames": "^2.2.6", "docsearch.js": "^2.5.2", + "infima": "0.2.0-alpha.1", "prism-react-renderer": "^0.1.6", "react-live": "^2.1.2", - "infima": "0.2.0-alpha.1", + "react-loadable": "^5.5.0", + "react-loadable-visibility": "^2.5.1", "react-toggle": "^4.0.2" }, "peerDependencies": { diff --git a/packages/docusaurus-theme-classic/src/theme/components/CodeBlock/index.js b/packages/docusaurus-theme-classic/src/theme/components/CodeBlock/index.js index 27da8c046b..ecbbdd947f 100644 --- a/packages/docusaurus-theme-classic/src/theme/components/CodeBlock/index.js +++ b/packages/docusaurus-theme-classic/src/theme/components/CodeBlock/index.js @@ -6,10 +6,17 @@ */ import React from 'react'; +import LoadableVisibility from 'react-loadable-visibility/react-loadable'; import Highlight, {defaultProps} from 'prism-react-renderer'; import nightOwlTheme from 'prism-react-renderer/themes/nightOwl'; -import Playground from '@theme/components/Playground'; +import Loading from '@theme/Loading'; + +/* Live playground is not small in size, lazy load it is better */ +const Playground = LoadableVisibility({ + loader: () => import('@theme/components/Playground'), + loading: Loading, +}); export default ({children, className: languageClassName, live, ...props}) => { if (live) { diff --git a/website/docs/writing-documentation.md b/website/docs/writing-documentation.md index 6e9f4c4441..e7133d2ea3 100644 --- a/website/docs/writing-documentation.md +++ b/website/docs/writing-documentation.md @@ -97,3 +97,74 @@ TODO: Talk more about using the official docs plugin and how to configure the si References: - https://docusaurus.io/docs/en/navigation --> + +## Syntax highlighting + +If you're writing technical documentation you may want a way to delineate blocks of +code, sometimes known as a *code fence*. The result is also known as a *code block*. +The simplest way to show code is to wrap it between two lines consisting of 3 backticks in a row. + +Example: + + ```jsx + console.log("Hello world"); + ``` + +And the result would be: + +```jsx +console.log("Hello world"); +``` + +## Live Editor + +You can also create live code editors with a code block `live` meta string. + +Example: + + ```jsx live + function Clock(props) { + const [date, setDate] = useState(new Date()); + useEffect(() => { + var timerID = setInterval(() => tick(), 1000); + + return function cleanup() { + clearInterval(timerID); + }; + }); + + function tick() { + setDate(new Date()); + } + + return ( +