This commit is contained in:
mgabdev
2020-04-22 01:00:11 -04:00
parent 4d7aee59c9
commit fed036be08
46 changed files with 883 additions and 1134 deletions

View File

@@ -2,8 +2,12 @@ import {
Editor,
EditorState,
CompositeDecorator,
RichUtils
RichUtils,
convertToRaw,
convertFromRaw
} from 'draft-js'
import { draftToMarkdown } from 'markdown-draft-js'
// import draftToMarkdown from 'draftjs-to-markdown'
import { urlRegex } from '../features/compose/util/url_regex'
import classNames from 'classnames/bind'
import RichTextEditorBar from './rich_text_editor_bar'
@@ -101,14 +105,34 @@ class Composer extends PureComponent {
onChange = (editorState) => {
this.setState({ editorState })
const text = editorState.getCurrentContent().getPlainText('\u0001')
const content = this.state.editorState.getCurrentContent();
const text = content.getPlainText('\u0001')
const selectionState = editorState.getSelection()
const selectionStart = selectionState.getStartOffset()
this.props.onChange(null, text, selectionStart)
const rawObject = convertToRaw(content);
const markdownString = draftToMarkdown(rawObject);
// const markdownString = draftToMarkdown(rawObject, {
// trigger: '#',
// separator: ' ',
// });
console.log("markdownString:", markdownString)
this.props.onChange(null, text, selectionStart, markdownString)
}
// **bold**
// *italic*
// __underline__
// ~strikethrough~
// # title
// > quote
// `code`
// ```code```
focus = () => {
this.textbox.editor.focus()
}