Skip to content

Commit bd358d9

Browse files
committed
fix rendering DraftJS message when block doesn't have inline content
1 parent 8ee5337 commit bd358d9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/helpers/markdownToState.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {convertFromRaw} from 'draft-js'
2-
import _ from 'lodash'
32
const Remarkable = require('remarkable')
43

54
// Block level items, key is Remarkable's key for them, value returned is
@@ -285,7 +284,12 @@ function markdownToState(markdown, options = {}) {
285284
// but right now this code doesn't support that.
286285
if (item.level === 0 || item.type === 'list_item_open') {
287286
const block = Object.assign({
288-
depth: 0
287+
depth: 0,
288+
// set default values when creating a block, usually the block would have some inline items and
289+
// so these default values would be overwritten because of inline items by `blockToModify` object above
290+
text: '',
291+
inlineStyleRanges: [],
292+
entityRanges: [],
289293
}, BlockTypes[itemType](item))
290294

291295
blocks.push(block)
@@ -295,7 +299,7 @@ function markdownToState(markdown, options = {}) {
295299

296300
return convertFromRaw({
297301
entityMap,
298-
blocks: _.filter(blocks, b => b.text)
302+
blocks,
299303
})
300304
}
301305

0 commit comments

Comments
 (0)