Skip to content

Commit

Permalink
Refs #25217 - Refactor Markdown prop-types
Browse files Browse the repository at this point in the history
* Adds default-props
* Convert to functional component
  • Loading branch information
Avi Sharvit authored and ohadlevy committed Nov 26, 2018
1 parent 741595d commit 6a9879c
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions webpack/stories/components/Markdown/Markdown.js
Expand Up @@ -4,30 +4,32 @@ import hljs from 'highlight.js';
import Remarkable from 'react-remarkable';
import './Markdown.scss';

class Markdown extends React.Component {
render() {
const options = {
html: true,
breaks: true,
linkTarget: '_parent',
highlight(code, lang) {
if (lang !== undefined) {
return hljs.highlight(lang, code).value;
}
return '';
},
};
const Markdown = ({ source }) => {
const options = {
html: true,
breaks: true,
linkTarget: '_parent',
highlight(code, lang) {
if (lang !== undefined) {
return hljs.highlight(lang, code).value;
}
return '';
},
};

return (
<div className="markdown-body">
<Remarkable source={this.props.source} options={options}/>
</div>
);
}
}
return (
<div className="markdown-body">
<Remarkable source={source} options={options} />
</div>
);
};

Markdown.propTypes = {
source: PropTypes.string,
};

Markdown.defaultProps = {
source: '',
};

export default Markdown;

0 comments on commit 6a9879c

Please sign in to comment.