diff options
author | Samy Pessé <samypesse@gmail.com> | 2017-02-26 22:35:51 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2017-02-26 22:35:51 +0100 |
commit | d640636784bc86bcbe56f77c0455b19b22fe0e6f (patch) | |
tree | 6c3871d4680d4f0dca462378fb5b5d975249a890 /packages/gitbook-core/src/components/PageContent.js | |
parent | 36b00d6cf2d521bdcfe2d954a02d6716c9de923e (diff) | |
download | gitbook-d640636784bc86bcbe56f77c0455b19b22fe0e6f.zip gitbook-d640636784bc86bcbe56f77c0455b19b22fe0e6f.tar.gz gitbook-d640636784bc86bcbe56f77c0455b19b22fe0e6f.tar.bz2 |
Start removing nunjucks
Diffstat (limited to 'packages/gitbook-core/src/components/PageContent.js')
-rw-r--r-- | packages/gitbook-core/src/components/PageContent.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/components/PageContent.js b/packages/gitbook-core/src/components/PageContent.js new file mode 100644 index 0000000..b0998ef --- /dev/null +++ b/packages/gitbook-core/src/components/PageContent.js @@ -0,0 +1,94 @@ +const React = require('react'); +const ImmutablePropTypes = require('react-immutable-proptypes'); + +const NODES = { + // Blocks + heading_one: props => <h1>{props.children}</h1>, + heading_two: props => <h2>{props.children}</h2>, + heading_three: props => <h3>{props.children}</h3>, + heading_four: props => <h4>{props.children}</h4>, + heading_five: props => <h5>{props.children}</h5>, + heading_six: props => <h6>{props.children}</h6>, + paragraph: props => <p>{props.children}</p> +}; + +const MARKS = { + BOLD: props => <b>{props.children}</b>, + ITALIC: props => <em>{props.children}</em>, + STRIKETHROUGH: props => <del>{props.children}</del>, + CODE: props => <code>{props.children}</code> +}; + + +/** + * Render a text node. + * @type {ReactClass} + */ +const Text = React.createClass({ + propTypes: { + node: React.PropTypes.object.isRequired + }, + + render() { + const { node } = this.props; + const ranges = node.get('ranges'); + + return ( + <div> + + </div> + ); + } +}); + +/** + * Inner content of a page. + * @type {ReactClass} + */ +const Node = React.createClass({ + propTypes: { + node: React.PropTypes.object.isRequired + }, + + render() { + const { node } = this.props; + + const children = node + .get('children') + .map((child) => { + if (child.kind == 'text') { + return <Text node={child} />; + } else { + return <Node node={child} />; + } + }) + .toArray(); + + return React.createElement( + NODES[node.type], + { + node + }, + children + ); + } +}); + +/** + * Inner content of a page. + * @type {ReactClass} + */ +const PageContent = React.createClass({ + propTypes: { + document: React.PropTypes.object.isRequired + }, + + render() { + const { document } = this.props; + return ( + <Node node={document} /> + ); + } +}); + +module.exports = PageContent; |