Rosey / markdown-draft-js

A tool to convert content created in DraftJS to markdown and vice versa.
https://rosey.github.io/markdown-draft-js/
MIT License
318 stars 70 forks source link

Empty title tags '#' give error when converted to draftJS #17

Closed joepio closed 7 years ago

joepio commented 7 years ago

First of all, thank you so much for sharing this plugin!

An error occurs when a markdown line is converted to DraftJS with one or multiple # symbols that is not followed by regular characters. A header block is created, but since it does not have a text attribute, it's length cannot be calculated.

Uncaught TypeError: Cannot read property 'length' of undefined
    at decodeInlineStyleRanges (webpack:///./~/draft-js/lib/decodeInlineStyleRanges.js?:30:26)
    at eval (webpack:///./~/draft-js/lib/convertFromRawToDraftState.js?:66:24)
    at Array.map (native)
    at Object.convertFromRawToDraftState [as convertFromRaw] (webpack:///./~/draft-js/lib/convertFromRawToDraftState.js?:50:30)
    at createDraftFromMarkdown (webpack:///./app/helpers/markdownHelper.js?:20:76)
    at reducer (webpack:///./app/state/markdownEditor/reducer.js?:50:106)
    at eval (webpack:///./~/redux-immutable/dist/combineReducers.js?:37:31)
    at Array.forEach (native)
    at eval (webpack:///./~/redux-immutable/dist/combineReducers.js?:34:19)
    at Map.withMutations (webpack:///./~/immutable/dist/immutable.js?:1355:7)

The bug can be replicated like this

Draft.EditorState.createWithContent(Draft.convertFromRaw(markdownToDraft('#')))

If we take the constructed object, and add a text attribute string to the header block, there are no errors.

var object = markdownToDraft('#');
object.blocks[0].text = 'test' 
Draft.EditorState.createWithContent(Draft.convertFromRaw(object))

Perhaps the header block should contain an empty string as its text attribute.

Rosey commented 7 years ago

Darn sorry for such a long delay in my reply, I somehow missed the notification of this issue being opened and so I didn't even know there was anything to respond to until I was randomly viewing the repo this morning! Two months later 😳

Good bug report, I'll make sure it gets fixed 🙂 🐛

Rosey commented 7 years ago

Opened a PR :)