Skip to content

Commit

Permalink
Add a fix for inline spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadi Kraman committed Jul 5, 2018
1 parent bb25f15 commit f0481dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/draftjsToMd.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function draftjsToMd(raw, extraMarkdownDict) {
newText += endingStyle.symbol;

newText = fixWhitespacesInsideStyle(newText, endingStyle);
totalOffset += endingStyle.symbol.length;
}

return newText;
Expand Down
21 changes: 21 additions & 0 deletions test/draftjsToMd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,27 @@ describe('draftjsToMd', () => {
draftjsToMd(raw).should.equal(expectedMarkdown);
});

it('inline styles do not remove spaces', () => {
const raw = {
entityMap: {},
blocks: [
{
data: {},
depth: 0,
entityRanges: [],
inlineStyleRanges: [
{ offset: 0, length: 4, style: 'BOLD' },
{ offset: 12, length: 4, style: 'ITALIC' }
],
text: 'This is not fine',
type: 'unstyled'
}
]
};
const expectedMarkdown = '__This__ is not *fine*';
draftjsToMd(raw).should.equal(expectedMarkdown);
});

describe('custom markdownDict', () => {
const customMarkdownDict = {
BOLD: '**',
Expand Down

0 comments on commit f0481dc

Please sign in to comment.