Skip to content

Commit

Permalink
Override default code-block element. Fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Feb 8, 2017
1 parent dcab498 commit 431c3fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/api/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export default {
getBlockRenderMap(blockTypes = []) {
const renderMap = {};

// Override default element for code block.
// Fix https://github.com/facebook/draft-js/issues/406.
if (blockTypes.some(block => block.type === BLOCK_TYPE.CODE)) {
renderMap[BLOCK_TYPE.CODE] = {
element: 'code',
wrapper: DefaultDraftBlockRenderMap.get(BLOCK_TYPE.CODE).wrapper,
};
}

blockTypes.filter(block => block.element)
.forEach((block) => {
renderMap[block.type] = { element: block.element };
Expand Down
14 changes: 14 additions & 0 deletions lib/api/behavior.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ describe('behavior', () => {
{ type: 'TEST' },
]).get('TEST')).not.toBeDefined();
});

describe('code block element', () => {
it('default is "code"', () => {
expect(behavior.getBlockRenderMap([
{ type: BLOCK_TYPE.CODE },
]).get(BLOCK_TYPE.CODE).element).toEqual('code');
});

it('can be overriden', () => {
expect(behavior.getBlockRenderMap([
{ type: BLOCK_TYPE.CODE, element: 'span' },
]).get(BLOCK_TYPE.CODE).element).toEqual('span');
});
});
});

describe('#getBlockStyleFn', () => {
Expand Down

0 comments on commit 431c3fd

Please sign in to comment.