Skip to content

Commit 9e2c3f1

Browse files
committed
Add inline style support
1 parent 420032f commit 9e2c3f1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/library/__tests__/mainTest.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ describe('htmlToDraft test suite', () => {
2424
contentBlocks = htmlToDraft('<p>test<a>link</a></p>');
2525
console.log('contentBlocks', contentBlocks);
2626

27+
contentBlocks = htmlToDraft(`<span style="font-weight:bold;">bold</span>`);
28+
console.log('contentBlocks', contentBlocks);
29+
30+
contentBlocks = htmlToDraft(`<span style="text-decoration:underline;">underline</span>`);
31+
console.log('contentBlocks', contentBlocks);
32+
33+
contentBlocks = htmlToDraft(`<span style="font-style:italic;">italic</span>`);
34+
console.log('contentBlocks', contentBlocks);
35+
2736
assert.equal(true, true);
2837
});
2938
});

src/library/processInlineTag.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default function processInlineTag(
2525
const backgroundColor = htmlElement.style.backgroundColor;
2626
const fontSize = htmlElement.style.fontSize;
2727
const fontFamily = htmlElement.style.fontFamily.replace(/^"|"$/g, '');
28+
const fontWeight = htmlElement.style.fontWeight;
29+
const textDecoration = htmlElement.style.textDecoration;
30+
const fontStyle = htmlElement.style.fontStyle;
2831
if (color) {
2932
style.add(`color-${color.replace(/ /g, '')}`);
3033
}
@@ -37,6 +40,15 @@ export default function processInlineTag(
3740
if (fontFamily) {
3841
style.add(`fontfamily-${fontFamily}`);
3942
}
43+
if(fontWeight === 'bold'){
44+
style.add(inlineTags.strong)
45+
}
46+
if(textDecoration === 'underline'){
47+
style.add(inlineTags.ins)
48+
}
49+
if(fontStyle === 'italic'){
50+
style.add(inlineTags.em)
51+
}
4052
}).toOrderedSet();
4153
}
4254
return inlineStyle;

0 commit comments

Comments
 (0)