Skip to content

Commit e27e0c7

Browse files
authored
Merge pull request #38 from MYOB-Technology/feature/style-support
Add inline style support
2 parents c9fae8d + 0ec1e57 commit e27e0c7

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/library/__tests__/mainTest.js

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

27-
contentBlocks = htmlToDraft('<hr/>', function(nodeName) {
28-
if (nodeName === 'hr') {
29-
return {
30-
type: 'HORIZONTAL_RULE',
31-
mutability: 'IMMUTABLE',
32-
data: {}
33-
};
34-
}
35-
});
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>`);
3634
console.log('contentBlocks', contentBlocks);
3735

3836
assert.equal(true, true);

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)