mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-02 16:04:04 +03:00
fix lint error, move helper methods to char and token files
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
describe('React BBCode', () => {
|
||||
|
||||
test('render markup properly', () => {
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,5 +12,13 @@
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bbob/html": "^1.0.1",
|
||||
"prop-types": "^15.6.1",
|
||||
"react": "^15.6.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "15.x"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user