Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joepio opened this issue Jul 5, 2017 · 2 comments
Closed

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

joepio opened this issue Jul 5, 2017 · 2 comments
Labels

Comments

@joepio
Copy link

joepio commented Jul 5, 2017

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
Copy link
Owner

Rosey commented Sep 5, 2017

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 pushed a commit that referenced this issue Sep 7, 2017
As reported here: #17

DraftJS `convertFromRaw` expects headings and blockquotes to always have `text`
defined, which was not the case if the markdown string was something like a
single `#` or `>`.

By defining the text value by default to be an empty string, we get around this
issue, and the empty string will under normal circumstances still be replaced by
the proper content if there is any.
@Rosey
Copy link
Owner

Rosey commented Sep 7, 2017

Opened a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants