Skip to content

Commit

Permalink
Merge pull request #37 from kadikraman/bugfix/inline-code
Browse files Browse the repository at this point in the history
Parse inline code correctly
  • Loading branch information
kadikraman authored Jun 1, 2018
2 parents 59d2460 + 6fe223d commit 9eecdcf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mdToDraftjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ const parseMdLine = (line, existingEntities, extraStyles = {}) => {
} else {
if (style) {
addInlineStyleRange(text.length, child.value.length, style.type);
} else if (inlineStyles[child.type]) {
addInlineStyleRange(text.length, child.value.length, inlineStyles[child.type].type);
}
text = `${text}${
child.type === 'Image' || videoShortcodeRegEx.test(child.raw) ? ' ' : child.value
Expand Down
27 changes: 27 additions & 0 deletions test/mdToDraftjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,31 @@ describe('mdToDraftjs', () => {
};
mdToDraftjs(markdown).should.deep.equal(expectedDraftjs);
});

it('parses inline code correctly', () => {
const markdown = '`code`';
const expectedDraftjs = {
blocks: [
{
text: 'code',
type: 'unstyled',
depth: 0,
inlineStyleRanges: [{ 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 9eecdcf

Please sign in to comment.