allow links to be wrapped in marks

This commit is contained in:
Shawn Erquhart 2017-09-05 22:57:01 -07:00
parent cd111f3a3d
commit e54dee4220
2 changed files with 26 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import React from 'react';
import { List } from 'immutable';
import cn from 'classnames';
import styles from './index.css';
@ -34,10 +35,17 @@ export const NODE_COMPONENTS = {
'numbered-list': props =>
<ol {...props.attributes} start={props.node.data.get('start') || 1}>{props.children}</ol>,
'link': props => {
// Need to wrap this in mark components for any marks found in data.
const data = props.node.get('data');
const marks = data.get('marks');
const url = data.get('url');
const title = data.get('title');
return <a href={url} title={title} {...props.attributes}>{props.children}</a>;
const link = <a href={url} title={title} {...props.attributes}>{props.children}</a>;
const result = !marks ? link : marks.reduce((acc, mark) => {
const MarkComponent = MARK_COMPONENTS[mark.type];
return <MarkComponent>{acc}</MarkComponent>;
}, link);
return result;
},
'shortcode': props => {
const { attributes, node, state: editorState } = props;

View File

@ -0,0 +1,17 @@
import { flow } from 'lodash';
import { markdownToSlate, slateToMarkdown } from '../index';
const process = flow([markdownToSlate, slateToMarkdown]);
describe('slate', () => {
it('should distinguish between newlines and hard breaks', () => {
expect(process('a\n')).toEqual('a\n');
});
it('should not decode encoded html entities in inline code', () => {
expect(process('<code>&lt;div&gt;</code>')).toEqual('<code>&lt;div&gt;</code>\n');
});
it('should parse non-text children of mark nodes', () => {
expect(process('**[a](b)**')).toEqual('**[a](b)**');
});
});