Extracted renderToken function from class. Do not render additional <div>
.
This commit is contained in:
parent
2c483220b5
commit
7fe1a6f8b6
@ -21,9 +21,7 @@ const defaultRenderers = {
|
||||
'unstyled': null,
|
||||
};
|
||||
|
||||
export default class MarkitupReactRenderer extends React.Component {
|
||||
|
||||
renderToken = (token) => {
|
||||
function renderToken(token) {
|
||||
const { type, data, text, tokens } = token;
|
||||
const element = defaultRenderers[type];
|
||||
|
||||
@ -31,7 +29,7 @@ export default class MarkitupReactRenderer extends React.Component {
|
||||
if (typeof element !== 'undefined') {
|
||||
let children = null;
|
||||
if (Array.isArray(tokens) && tokens.length) {
|
||||
children = tokens.map(this.renderToken);
|
||||
children = tokens.map(renderToken);
|
||||
} else if (type === 'text') {
|
||||
children = text;
|
||||
}
|
||||
@ -44,7 +42,9 @@ export default class MarkitupReactRenderer extends React.Component {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default class MarkitupReactRenderer extends React.Component {
|
||||
|
||||
render() {
|
||||
const { value, syntax } = this.props;
|
||||
@ -57,9 +57,7 @@ export default class MarkitupReactRenderer extends React.Component {
|
||||
const json = JSONUtils.encode(content);
|
||||
// console.log(JSON.stringify(json, null, 2));
|
||||
|
||||
return (
|
||||
<div>{this.renderToken(json.token)}</div>
|
||||
);
|
||||
return renderToken(json.token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,7 @@ Text with **bold** & _em_ elements
|
||||
});
|
||||
|
||||
it('should support custom syntax', () => {
|
||||
const value = `
|
||||
`;
|
||||
const value = '';
|
||||
const component = renderer.create(
|
||||
<MarkitupReactRenderer
|
||||
value={value}
|
||||
|
@ -1,6 +1,5 @@
|
||||
exports[`MarkitupReactRenderer should render HTML 1`] = `
|
||||
<div>
|
||||
<article>
|
||||
<article>
|
||||
<p>
|
||||
Paragraph with
|
||||
<em>
|
||||
@ -8,13 +7,11 @@ exports[`MarkitupReactRenderer should render HTML 1`] = `
|
||||
</em>
|
||||
element
|
||||
</p>
|
||||
</article>
|
||||
</div>
|
||||
</article>
|
||||
`;
|
||||
|
||||
exports[`MarkitupReactRenderer should render markdown 1`] = `
|
||||
<div>
|
||||
<article>
|
||||
<article>
|
||||
<h1
|
||||
id={null}>
|
||||
H1
|
||||
@ -85,6 +82,7 @@ exports[`MarkitupReactRenderer should render markdown 1`] = `
|
||||
id={null}>
|
||||
H6
|
||||
</h6>
|
||||
</article>
|
||||
</div>
|
||||
</article>
|
||||
`;
|
||||
|
||||
exports[`MarkitupReactRenderer should support custom syntax 1`] = `<article />`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user