Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple inlineStyles to be returned by customInlineFn #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -341,7 +341,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