2016-08-03 10:30:42 -03:00
|
|
|
import React from 'react';
|
|
|
|
import Block from './Block';
|
2016-08-08 18:51:53 -03:00
|
|
|
import styles from '../MarkdownControl.css';
|
2016-08-03 10:30:42 -03:00
|
|
|
|
|
|
|
/* eslint react/prop-types: 0, react/no-multi-comp: 0 */
|
|
|
|
|
|
|
|
// Define the default node type.
|
|
|
|
export const DEFAULT_NODE = 'paragraph';
|
|
|
|
|
|
|
|
// Local node renderers.
|
|
|
|
export const NODES = {
|
2016-08-10 18:59:56 -03:00
|
|
|
'blockquote': (props) => <Block type='blockquote' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'unordered_list': props => <Block type='List'><ul {...props.attributes}>{props.children}</ul></Block>,
|
|
|
|
'header_one': props => <Block type='Heading1' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'header_two': props => <Block type='Heading2' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'header_three': props => <Block type='Heading2' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'header_four': props => <Block type='Heading2' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'header_five': props => <Block type='Heading2' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'header_six': props => <Block type='Heading2' {...props.attributes}>{props.children}</Block>,
|
|
|
|
'list_item': props => <li {...props.attributes}>{props.children}</li>,
|
2016-08-03 10:30:42 -03:00
|
|
|
'paragraph': props => <Block type='Paragraph' {...props.attributes}>{props.children}</Block>,
|
2016-08-10 18:59:56 -03:00
|
|
|
'hr': props => {
|
2016-08-08 11:57:49 -03:00
|
|
|
const { node, state } = props;
|
|
|
|
const isFocused = state.selection.hasEdgeIn(node);
|
|
|
|
const className = isFocused ? styles.active : null;
|
|
|
|
return (
|
|
|
|
<hr className={className} {...props.attributes} />
|
|
|
|
);
|
|
|
|
},
|
2016-08-03 10:30:42 -03:00
|
|
|
'link': (props) => {
|
|
|
|
const { data } = props.node;
|
|
|
|
const href = data.get('href');
|
2016-08-06 18:16:30 -03:00
|
|
|
return <a {...props.attributes} href={href}>{props.children}</a>;
|
2016-08-03 10:30:42 -03:00
|
|
|
},
|
|
|
|
'image': (props) => {
|
|
|
|
const { node } = props;
|
|
|
|
const src = node.data.get('src');
|
|
|
|
return (
|
|
|
|
<img {...props.attributes} src={src} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Local mark renderers.
|
|
|
|
export const MARKS = {
|
2016-08-10 18:59:56 -03:00
|
|
|
BOLD: {
|
2016-08-03 10:30:42 -03:00
|
|
|
fontWeight: 'bold'
|
|
|
|
},
|
2016-08-10 18:59:56 -03:00
|
|
|
ITALIC: {
|
2016-08-03 10:30:42 -03:00
|
|
|
fontStyle: 'italic'
|
|
|
|
},
|
2016-08-10 18:59:56 -03:00
|
|
|
CODE: {
|
2016-08-03 10:30:42 -03:00
|
|
|
fontFamily: 'monospace',
|
|
|
|
backgroundColor: '#eee',
|
|
|
|
padding: '3px',
|
|
|
|
borderRadius: '4px'
|
|
|
|
}
|
|
|
|
};
|