2018-09-24 15:36:35 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import marked from 'marked';
|
2019-08-29 21:41:21 +00:00
|
|
|
import Prism from 'prismjs';
|
|
|
|
import 'prismjs/components/prism-jsx';
|
2018-09-24 15:36:35 +00:00
|
|
|
|
2019-08-29 21:41:21 +00:00
|
|
|
// Alias `javascript` language to `es6`
|
|
|
|
Prism.languages.es6 = Prism.languages.javascript;
|
|
|
|
|
|
|
|
// Configure marked to use Prism for code-block highlighting.
|
|
|
|
marked.setOptions( {
|
2020-02-14 02:23:21 +00:00
|
|
|
highlight( code, language ) {
|
2019-08-29 21:41:21 +00:00
|
|
|
const syntax = Prism.languages[ language ];
|
|
|
|
return syntax ? Prism.highlight( code, syntax ) : code;
|
|
|
|
},
|
|
|
|
} );
|
2018-09-24 15:36:35 +00:00
|
|
|
|
|
|
|
class Docs extends Component {
|
|
|
|
state = {
|
|
|
|
readme: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.getReadme();
|
|
|
|
}
|
|
|
|
|
|
|
|
getReadme() {
|
2019-08-29 21:41:21 +00:00
|
|
|
const { filePath } = this.props;
|
2020-07-28 02:32:58 +00:00
|
|
|
const readme = require( `../../packages/components/src/${ filePath }/README.md` )
|
|
|
|
.default;
|
2019-08-29 21:41:21 +00:00
|
|
|
|
2018-09-24 15:36:35 +00:00
|
|
|
if ( ! readme ) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-29 21:41:21 +00:00
|
|
|
|
|
|
|
this.setState( { readme } );
|
2018-09-24 15:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { readme } = this.state;
|
|
|
|
if ( ! readme ) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-08-29 21:41:21 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="woocommerce-devdocs__docs"
|
|
|
|
//eslint-disable-next-line react/no-danger
|
|
|
|
dangerouslySetInnerHTML={ { __html: marked( readme ) } }
|
|
|
|
/>
|
|
|
|
);
|
2018-09-24 15:36:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Docs;
|