Skip to content

Allow multiple inlineStyles to be returned by customInlineFn #155 #1

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

Merged
merged 1 commit into from
Jul 29, 2020
Merged
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
@@ -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]);
2 changes: 1 addition & 1 deletion packages/draft-js-import-element/src/stateFromElement.js
Original file line number Diff line number Diff line change
@@ -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': {