allow links to be wrapped in marks
This commit is contained in:
parent
cd111f3a3d
commit
e54dee4220
@ -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;
|
||||
|
@ -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><div></code>')).toEqual('<code><div></code>\n');
|
||||
});
|
||||
|
||||
it('should parse non-text children of mark nodes', () => {
|
||||
expect(process('**[a](b)**')).toEqual('**[a](b)**');
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user