1.0.1 • Published 2 years ago
@draft-js-enhance-plugins/paste-html v1.0.1
DraftJS Paste HTML Plugin
This is a plugin for the @draft-js-plugins/editor
.
Feature
Convert HTML to ContentState
that has been pasted directly into the editor.
Refer to handlePastedText
.
Options
convertFromHTML
Type:
type convertFromHTML = (html: string) => ContentState;
Given an HTML fragment, convert it to a ContentState
.
Usage
import { EditorState } from 'draft-js';
import Editor from '@draft-js-plugins/editor';
import createPasteHTMLPlugin from '@draft-js-enhance-plugins/paste-html';
// See: https://www.npmjs.com/package/draft-convert
// import { convertFromHTML } from 'draft-convert';
const pasteHTMLPlugin = createPasteHTMLPlugin({ convertFromHTML });
const plugins = [pasteHTMLPlugin];
function Example() {
const [editorState, setEditorState] = useState(EditorState.createEmpty());
return (
<Editor
editorState={editorState}
onChange={setEditorState}
plugins={plugins}
/>
);
}