diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts
index 230271f8..fa2b0987 100644
--- a/packages/tiptap-core/src/Editor.ts
+++ b/packages/tiptap-core/src/Editor.ts
@@ -9,6 +9,7 @@ import {addListNodes} from "prosemirror-schema-list"
import {exampleSetup} from "prosemirror-example-setup"
import insertText from './commands/insertText'
+import insertHTML from './commands/insertHTML'
import focus from './commands/focus'
interface EditorOptions {
@@ -36,6 +37,7 @@ export class Editor {
this.view = this.createView()
this.registerCommand('focus', focus)
this.registerCommand('insertText', insertText)
+ this.registerCommand('insertHTML', insertHTML)
}
get state() {
diff --git a/packages/tiptap-core/src/commands/insertHTML.ts b/packages/tiptap-core/src/commands/insertHTML.ts
new file mode 100644
index 00000000..9fda10cb
--- /dev/null
+++ b/packages/tiptap-core/src/commands/insertHTML.ts
@@ -0,0 +1,22 @@
+import { DOMParser } from 'prosemirror-model'
+import { Editor } from '../Editor'
+
+declare module '../Editor' {
+ interface Editor {
+ insertHTML(value: string): 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 slice = DOMParser.fromSchema(state.schema).parseSlice(element)
+ const transaction = state.tr.insert(selection.anchor, slice.content)
+
+ view.dispatch(transaction)
+
+ next()
+}
\ No newline at end of file
diff --git a/packages/tiptap-core/src/commands/insertText.ts b/packages/tiptap-core/src/commands/insertText.ts
index 3de4f713..abc42d1a 100644
--- a/packages/tiptap-core/src/commands/insertText.ts
+++ b/packages/tiptap-core/src/commands/insertText.ts
@@ -1,12 +1,14 @@
import { Editor } from '../Editor'
-declare module "../Editor" {
+declare module '../Editor' {
interface Editor {
- insertText(text: string): Editor,
+ insertText(value: string): Editor,
}
}
-export default function insertText(next: Function, { state, view }: Editor, text: string): void {
- view.dispatch(state.tr.insertText(text))
+export default function insertText(next: Function, { state, view }: Editor, value: string): void {
+ const transaction = state.tr.insertText(value)
+
+ view.dispatch(transaction)
next()
}
diff --git a/src/templates/Post.vue b/src/templates/Post.vue
index 098aee20..72a9b5f1 100644
--- a/src/templates/Post.vue
+++ b/src/templates/Post.vue
@@ -2,6 +2,8 @@
{{ $page.post.title }}
test strong
', + }) + // .registerCommand('lol', (next) => { + // console.log('lol') + // next() + // }) + // .focus('end') + // .insertText('mega ') + // .focus('start') + // .command('insertText', 'giga ') + // .lol() + + // .registerCommand('insertHTML', (next, editor, html) => { + // console.log(html) + // next() + // }) + .focus('start') + .insertText('start
') + .focus('end') + .insertHTML('end
') } } \ No newline at end of file