refactoring

This commit is contained in:
Philipp Kühn
2019-12-16 23:51:18 +01:00
parent 60e31655a2
commit 48c7d4bb98
3 changed files with 30 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
import { DOMParser } from 'prosemirror-model'
import { Editor } from '../Editor'
import elementFromString from '../utils/elementFromString'
declare module '../Editor' {
interface Editor {
@@ -9,14 +10,10 @@ declare module '../Editor' {
export default function insertHTML(next: Function, { state, view }: Editor, value: string): void {
const { selection } = state
const element = document.createElement('div')
element.innerHTML = value.trim()
const element = elementFromString(value)
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
const transaction = state.tr.insert(selection.anchor, slice.content)
view.dispatch(transaction)
next()
}