@@ -19,7 +19,7 @@ import {isTextSelection, isNodeSelection, isWholeSelection} from '../../../utils
1919import { BaseNode , pType } from '../../base/BaseSchema' ;
2020
2121import { isInsideCode } from './code' ;
22- import { DataTransferType , isIosSafariShare } from './utils' ;
22+ import { DataTransferType , extractTextContentFromHtml , isIosSafariShare } from './utils' ;
2323
2424export type ClipboardPluginOptions = {
2525 yfmParser : Parser ;
@@ -99,12 +99,31 @@ export const clipboard = ({
9999 ! e . clipboardData . types . includes ( DataTransferType . Yfm ) &&
100100 ( data = e . clipboardData . getData ( DataTransferType . Html ) )
101101 ) {
102- return false ; // default html pasting
102+ const textFromHtml = extractTextContentFromHtml ( data ) ;
103+ if ( textFromHtml ) {
104+ const res = tryCatch ( ( ) => textParser . parse ( textFromHtml ) ) ;
105+ if ( res . success ) {
106+ const docNode = res . result ;
107+ const slice = getSliceFromMarkupFragment ( docNode . content ) ;
108+ view . dispatch (
109+ trackTransactionMetrics (
110+ view . state . tr . replaceSelection ( slice ) ,
111+ 'paste' ,
112+ { clipboardDataFormat : DataTransferType . Html } ,
113+ ) ,
114+ ) ;
115+ isPasteHandled = true ;
116+ } else {
117+ logger . error ( res . error ) ;
118+ console . error ( res . error ) ;
119+ }
120+ } else return false ; // default html pasting
103121 }
104122
105123 if (
106- ( data = e . clipboardData . getData ( DataTransferType . Yfm ) ) ||
107- ( data = e . clipboardData . getData ( DataTransferType . Text ) )
124+ ! isPasteHandled &&
125+ ( ( data = e . clipboardData . getData ( DataTransferType . Yfm ) ) ||
126+ ( data = e . clipboardData . getData ( DataTransferType . Text ) ) )
108127 ) {
109128 let parser : Parser ;
110129 let dataFormat : string ;
0 commit comments