From bd358d92244c065e76548313d4710a0a5e8e3575 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Thu, 25 Jul 2019 11:14:10 +0800 Subject: [PATCH] fix rendering DraftJS message when block doesn't have inline content --- src/helpers/markdownToState.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/helpers/markdownToState.js b/src/helpers/markdownToState.js index b0ecb7d44..1641b0bcd 100644 --- a/src/helpers/markdownToState.js +++ b/src/helpers/markdownToState.js @@ -1,5 +1,4 @@ import {convertFromRaw} from 'draft-js' -import _ from 'lodash' const Remarkable = require('remarkable') // Block level items, key is Remarkable's key for them, value returned is @@ -285,7 +284,12 @@ function markdownToState(markdown, options = {}) { // but right now this code doesn't support that. if (item.level === 0 || item.type === 'list_item_open') { const block = Object.assign({ - depth: 0 + depth: 0, + // set default values when creating a block, usually the block would have some inline items and + // so these default values would be overwritten because of inline items by `blockToModify` object above + text: '', + inlineStyleRanges: [], + entityRanges: [], }, BlockTypes[itemType](item)) blocks.push(block) @@ -295,7 +299,7 @@ function markdownToState(markdown, options = {}) { return convertFromRaw({ entityMap, - blocks: _.filter(blocks, b => b.text) + blocks, }) }