diff --git a/src/plugins/MarkdownPaste.ts b/src/plugins/MarkdownPaste.ts index a97e95d45..349ffc3cb 100644 --- a/src/plugins/MarkdownPaste.ts +++ b/src/plugins/MarkdownPaste.ts @@ -2,6 +2,7 @@ import { Plugin } from "prosemirror-state"; import { toggleMark } from "prosemirror-commands"; import Extension from "../lib/Extension"; import isUrl from "../lib/isUrl"; +import isInCode from "../queries/isInCode"; export default class MarkdownPaste extends Extension { get name() { @@ -69,6 +70,11 @@ export default class MarkdownPaste extends Extension { event.preventDefault(); + if (isInCode(view.state)) { + view.dispatch(view.state.tr.insertText(text)); + return true; + } + const paste = this.editor.parser.parse(text); const slice = paste.slice(0); diff --git a/src/queries/isInCode.ts b/src/queries/isInCode.ts new file mode 100644 index 000000000..f67ac64d9 --- /dev/null +++ b/src/queries/isInCode.ts @@ -0,0 +1,12 @@ +import isMarkActive from "./isMarkActive"; + +export default function isInCode(state) { + const $head = state.selection.$head; + for (let d = $head.depth; d > 0; d--) { + if ($head.node(d).type === state.schema.nodes.code_block) { + return true; + } + } + + return isMarkActive(state.schema.marks.code_inline)(state); +}