diff --git a/src/mdToDraftjs.js b/src/mdToDraftjs.js index b47c5a2..7acb779 100644 --- a/src/mdToDraftjs.js +++ b/src/mdToDraftjs.js @@ -180,7 +180,8 @@ const parseMdLine = (line, existingEntities, extraStyles = {}) => { } else { if (style) { addInlineStyleRange(text.length, child.value.length, style.type); - } else if (inlineStyles[child.type]) { + } + if (inlineStyles[child.type]) { addInlineStyleRange(text.length, child.value.length, inlineStyles[child.type].type); } text = `${text}${ diff --git a/test/mdToDraftjs.test.js b/test/mdToDraftjs.test.js index 526e6ee..245a370 100644 --- a/test/mdToDraftjs.test.js +++ b/test/mdToDraftjs.test.js @@ -761,6 +761,35 @@ describe('mdToDraftjs', () => { } }; + mdToDraftjs(markdown, customDict).should.deep.equal(expectedDraftjs); + }); + it('parses inline code mixed with other styles correctly', () => { + const markdown = '__`code`__'; + const expectedDraftjs = { + blocks: [ + { + text: 'code', + type: 'unstyled', + depth: 0, + inlineStyleRanges: [ + { offset: 0, length: 4, style: 'BOLD' }, + { offset: 0, length: 4, style: 'CODE' } + ], + entityRanges: [] + } + ], + entityMap: { data: '', mutability: '', type: '' } + }; + + const customDict = { + inlineStyles: { + Code: { + type: 'CODE', + symbol: '`' + } + } + }; + mdToDraftjs(markdown, customDict).should.deep.equal(expectedDraftjs); }); });