@@ -5,6 +5,7 @@ import type {
5
5
BlockNoteEditor ,
6
6
BlockNoteEditorOptions ,
7
7
} from "../../../editor/BlockNoteEditor" ;
8
+ import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js" ;
8
9
import {
9
10
BlockSchema ,
10
11
InlineContentSchema ,
@@ -13,7 +14,6 @@ import {
13
14
import { acceptedMIMETypes } from "./acceptedMIMETypes.js" ;
14
15
import { handleFileInsertion } from "./handleFileInsertion.js" ;
15
16
import { handleVSCodePaste } from "./handleVSCodePaste.js" ;
16
- import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js" ;
17
17
18
18
function defaultPasteHandler ( {
19
19
event,
@@ -26,6 +26,24 @@ function defaultPasteHandler({
26
26
prioritizeMarkdownOverHTML : boolean ;
27
27
plainTextAsMarkdown : boolean ;
28
28
} ) {
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
+
29
47
let format : ( typeof acceptedMIMETypes ) [ number ] | undefined ;
30
48
for ( const mimeType of acceptedMIMETypes ) {
31
49
if ( event . clipboardData ! . types . includes ( mimeType ) ) {
0 commit comments