2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-08 17:22:26 +03:00

fix lint error, move helper methods to char and token files

This commit is contained in:
Nikolay Kostyurin
2018-06-12 19:07:25 +02:00
parent 77ddfca271
commit a5d3fea566
13 changed files with 349 additions and 339 deletions
+29 -23
View File
@@ -1,41 +1,47 @@
const React = require('react');
const parse = require('bbob-html');
const PropTypes = require('prop-types');
const parse = require('@bbob/html');
class BBCode extends React.Component {
render() {
const Container = this.props.container;
return (
<Container>
{this.content()}
</Container>
);
}
content() {
if (this.props.source) {
// eslint-disable-next-line react/no-danger
return <span dangerouslySetInnerHTML={{ __html: this.renderBBCode(this.props.source) }} />;
}
else {
return React.Children.map(this.props.children, child => {
if (typeof child === 'string') {
return <span dangerouslySetInnerHTML={{ __html: this.renderBBCode(child) }} />;
}
else {
return child;
}
});
}
return React.Children.map(this.props.children, (child) => {
if (typeof child === 'string') {
// eslint-disable-next-line react/no-danger
return <span dangerouslySetInnerHTML={{ __html: this.renderBBCode(child) }} />;
}
return child;
});
}
renderBBCode(source) {
return parse(source)
return parse(source, this.props.options);
}
render() {
const Container = this.props.container;
return (<Container>{this.content()}</Container>);
}
}
BBCode.propTypes = {
container: PropTypes.node,
children: PropTypes.element.isRequired,
source: PropTypes.string,
options: PropTypes.shape({
prop: PropTypes.bool,
}),
};
BBCode.defaultProps = {
container: 'div',
options: {},
source: null,
};
module.exports = BBCode;
module.exports = BBCode;