refactor(v2): move livecodeblock as plugin (#1566)

* refactor(v2): move livecodeblock as plugin

* tweak from rebase

* nits

* nits

* dep
This commit is contained in:
Endi 2019-06-06 15:49:11 +07:00 committed by GitHub
parent a0777f7c57
commit 5362c2cda2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 208 additions and 72 deletions

View file

@ -7,29 +7,11 @@
import React from 'react';
import classnames from 'classnames';
import LoadableVisibility from 'react-loadable-visibility/react-loadable';
import Highlight, {defaultProps} from 'prism-react-renderer';
import nightOwlTheme from 'prism-react-renderer/themes/nightOwl';
import Loading from '@theme/Loading';
import styles from './styles.module.css';
/* Live playground is not small in size, lazy load it is better */
const Playground = LoadableVisibility({
loader: () => import('@theme/Playground'),
loading: Loading,
});
export default ({children, className: languageClassName, live, ...props}) => {
if (live) {
return (
<Playground
scope={{...React}}
code={children.trim()}
theme={nightOwlTheme}
{...props}
/>
);
}
export default ({children, className: languageClassName}) => {
const language =
languageClassName && languageClassName.replace(/language-/, '');
return (