Skip to content

Commit

Permalink
Allow multiple inlineStyles to be returned by customInlineFn sstur#155
Browse files Browse the repository at this point in the history
  • Loading branch information
msk-psp committed Jul 29, 2020
1 parent 7318dce commit 97e75f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@ describe('stateFromElement', () => {
});
});

it('should return multiple style from customInlineFn', () => {
let element = new ElementNode('div', [], [
new ElementNode(
'span',
[{style: 'font-family', value: 'sans-serif'},{style: 'font-size', value: '12px'},],
[new TextNode('Hello')]
)
]);
let options = {
customInlineFn(el, {Style}) {
if (el.tagName === 'SPAN') {
return Style(['CUSTOM_STYLE_1', 'CUSTOM_STYLE_2']);
}
},
};
let contentState = stateFromElement(element, options);
let rawContentState = removeBlockKeys(convertToRaw(contentState));
expect(rawContentState).toEqual({
entityMap: {},
blocks: [
{
text: 'Hello',
type: 'unstyled',
depth: 0,
inlineStyleRanges: [
{offset: 0, length: 5, style: 'CUSTOM_STYLE_1'},
{offset: 0, length: 5, style: 'CUSTOM_STYLE_2'}
],
entityRanges: [],
data: {},
},
],
});
});

it('should support option elementStyles', () => {
let textNode = new TextNode('Superscript');
let element = new ElementNode('sup', [], [textNode]);
Expand Down
2 changes: 1 addition & 1 deletion packages/draft-js-import-element/src/stateFromElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ContentGenerator {
if (customInline != null) {
switch (customInline.type) {
case 'STYLE': {
style = style.add(customInline.style);
[].concat(customInline.style).forEach(customStyle => style = style.add(customStyle));
break;
}
case 'ENTITY': {
Expand Down

0 comments on commit 97e75f9

Please sign in to comment.