allow passing html strings to setContent
This commit is contained in:
@@ -255,10 +255,25 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
getDocFromContent(content) {
|
||||
if (typeof content === 'object') {
|
||||
return this.schema.nodeFromJSON(content)
|
||||
}
|
||||
|
||||
if (typeof content === 'string') {
|
||||
const element = document.createElement('div')
|
||||
element.innerHTML = content.trim()
|
||||
|
||||
return DOMParser.fromSchema(this.schema).parse(element)
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
setContent(content = {}, emitUpdate = false) {
|
||||
this.state = EditorState.create({
|
||||
schema: this.state.schema,
|
||||
doc: this.schema.nodeFromJSON(content),
|
||||
doc: this.getDocFromContent(content),
|
||||
plugins: this.state.plugins,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user