Skip to content

Commit

Permalink
Allow adding style for lowest level children (#47)
Browse files Browse the repository at this point in the history
* Update mdToDraftjs.js

* remove change; add failing test case

* reintroduce change to fix failing test
  • Loading branch information
nsuthar0914 authored and kadikraman committed Feb 18, 2019
1 parent d12cbc4 commit a478799
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mdToDraftjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}${
Expand Down
29 changes: 29 additions & 0 deletions test/mdToDraftjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit a478799

Please sign in to comment.