draft-js-markdown-shortcuts-plugin icon indicating copy to clipboard operation
draft-js-markdown-shortcuts-plugin copied to clipboard

How to init with pre content?

Open zfha opened this issue 5 years ago • 2 comments

As the question

zfha avatar Dec 20 '18 11:12 zfha

Import the following

import { EditorState, ContentState } from 'draft-js';

After that, you can set the content in a constructor (or differently) by:

this.state = {
   editorState: EditorState.createWithContent(ContentState.createFromText("hello"))
};

However, adding markdown text in the createFromText function doesn't trigger parsing from the plugin, which I would love the developer to document or chime in on.

adamblvck avatar Jul 26 '19 16:07 adamblvck

Found a solution to problem specified above:

Install

npm install --save draft-js-import-markdown

Then you can set the content state as such:

this.state = {
   editorState: EditorState.createWithContent(stateFromMarkdown("#markdowntitle"))
};

adamblvck avatar Jul 26 '19 16:07 adamblvck