@@ -5,6 +5,7 @@ import type {
55 BlockNoteEditor ,
66 BlockNoteEditorOptions ,
77} from "../../../editor/BlockNoteEditor" ;
8+ import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js" ;
89import {
910 BlockSchema ,
1011 InlineContentSchema ,
@@ -13,7 +14,6 @@ import {
1314import { acceptedMIMETypes } from "./acceptedMIMETypes.js" ;
1415import { handleFileInsertion } from "./handleFileInsertion.js" ;
1516import { handleVSCodePaste } from "./handleVSCodePaste.js" ;
16- import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js" ;
1717
1818function defaultPasteHandler ( {
1919 event,
@@ -26,6 +26,24 @@ function defaultPasteHandler({
2626 prioritizeMarkdownOverHTML : boolean ;
2727 plainTextAsMarkdown : boolean ;
2828} ) {
29+ // Special case for code blocks, as they do not support any rich text
30+ // formatting, so we force pasting plain text.
31+ const isInCodeBlock = editor . transact (
32+ ( tr ) =>
33+ tr . selection . $from . parent . type . spec . code &&
34+ tr . selection . $to . parent . type . spec . code
35+ ) ;
36+
37+ if ( isInCodeBlock ) {
38+ const data = event . clipboardData ?. getData ( "text/plain" ) ;
39+
40+ if ( data ) {
41+ editor . pasteText ( data ) ;
42+
43+ return true ;
44+ }
45+ }
46+
2947 let format : ( typeof acceptedMIMETypes ) [ number ] | undefined ;
3048 for ( const mimeType of acceptedMIMETypes ) {
3149 if ( event . clipboardData ! . types . includes ( mimeType ) ) {
0 commit comments