Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
element = 'span';
}
// Normalize `className` -> `class`, etc.
attributes = normalizeAttributes(attributes);
if (style != null) {
let styleAttr = styleToCSS(style);
attributes = (attributes == null) ? {style: styleAttr} : {...attributes, style: styleAttr};
}
let attrString = stringifyAttrs(attributes);
content = `<${element}${attrString}>${content}`;
}
}
return content;
}).join('');
let entity = entityKey ? Entity.get(entityKey) : null;
// Note: The `toUpperCase` below is for compatability with some libraries that use lower-case for image blocks.
let entityType = (entity == null) ? null : entity.getType().toUpperCase();
if (entityType == null) {
return content;
}
let renderer = (entityRenderers != null && entityRenderers.hasOwnProperty(entityType)) ?
entityRenderers[entityType] :
null;
if (renderer == null) {
return content;
}
let attributes = convertDataToAttr(entity, renderer.attributeMap);
renderBlock: Function = (block): void => {
if (block.getType() === 'atomic') {
const entityType = Entity.get(block.getEntityAt(0)).getType();
return this.props.customBlocks[entityType] ? this.props.customBlocks[entityType].getBlockRenderer() : null;
}
// fall back to default renderer
return null;
}
/**
it('handles an inline image', () => {
const html = '<div>test<img src="test">test</div>';
const contentState = toContentState(html);
const blocks = contentState.getBlocksAsArray();
expect(blocks.length).toBe(3);
expect(blocks[1].getType()).toBe('atomic');
expect(Entity.get(blocks[1].getEntityAt(0)).getType()).toBe('IMAGE');
const resultHTML = convertToHTML({
blockToHTML: {
'atomic': {
start: '<figure>',
end: '</figure>'
}
},
entityToHTML: (entity, originalText) => {
if (entity.type === 'IMAGE') {
return `<img src="${entity.data.src}">`;
}
return originalText;
}
})(contentState);
expect(resultHTML).toBe('<p>test</p><figure><img src="test"></figure><p>test</p>');
});
const Link = (props) => {
const {href} = Entity.get(props.entityKey).getData();
return (
<a href="{href}">
{props.children}
</a>
);
};
const decorator = new CompositeDecorator([{
(character) => {
const entityKey = character.getEntity();
return (
entityKey !== null &&
Entity.get(entityKey).getType() === 'LINK'
);
},
callback,
(character) => {
const entityKey = character.getEntity();
return entityKey !== null && Entity.get(entityKey).getType() === 'link';
},
(start, end)=>{
_getValue() {
return Entity
.get(this.props.block.getEntityAt(0))
.getData()['content'];
}
render() {
const { editable } = this.props.blockProps;
const entity = Entity.get(this.props.block.getEntityAt(0));
const type = entity.getType();
switch (type) {
case Types.IMAGE: {
const { src, title, width, height } = entity.getData();
return this._renderComponent(
<img draggable="{editable}" height="{height}" width="{width}" title="{title}" src="{src}">
, entity.getData());
}
default:
_getCurrentUrl() {
let url;
const { editorState } = this.props;
const selection = editorState.getSelection();
const blockContent = editorState.getCurrentContent()
.getBlockForKey(selection.getAnchorKey());
const linkEntityRanges = findLinkEntityRangesIn(blockContent);
if (linkEntityRanges.length === 1 && matchesExactly(selection, linkEntityRanges[0])) {
const entityKey = blockContent.getEntityAt(0);
const entity = entityKey ? Entity.get(entityKey) : null;
url = entity && entity.getType() === Types.LINK ? entity.getData().href : '';
} else {
url = '';
}
return url;
}
getProps(props) {
const {
linkTitle, href, linkDesc, editCallback,
} = Entity.get(props.entityKey).getData();
return {
linkTitle: props.decoratedText || linkTitle,
href,
linkDesc,
entityKey: props.entityKey,
linkCallback: linkEditCallback,
};
}