@@ -2,6 +2,9 @@ import { Editor, Extension } from '@tiptap/core'
22import { Fragment , Node } from '@tiptap/pm/model'
33import { Plugin } from 'prosemirror-state'
44import { youtubeParser } from '@/components/Editor/types/utils'
5+ import { BlockNoteEditor } from '../../BlockNoteEditor'
6+ import { getBlockInfoFromPos } from '@/lib/utils'
7+ import * as BlockUtils from '@/lib/utils/block-utils'
58
69function containsMarkdownSymbols ( pastedText : string ) {
710 // Regex to detect unique Markdown symbols at the start of a line
@@ -53,7 +56,7 @@ function getPastedNodes(parent: Node | Fragment, editor: Editor) {
5356 return nodes
5457}
5558
56- const createMarkdownExtension = ( ) => {
59+ const createMarkdownExtension = ( bnEditor : BlockNoteEditor ) => {
5760 const MarkdownExtension = Extension . create ( {
5861 name : 'MarkdownPasteHandler' ,
5962 priority : 900 ,
@@ -76,6 +79,7 @@ const createMarkdownExtension = () => {
7679 const { selection } = state
7780
7881 const isMarkdown = pastedHtml ? containsMarkdownSymbols ( pastedText ) : true
82+
7983 if ( ! isMarkdown ) {
8084 if ( hasList ) {
8185 const firstBlockGroup = slice . content . firstChild ?. type . name === 'blockGroup'
@@ -96,7 +100,6 @@ const createMarkdownExtension = () => {
96100 }
97101 return false
98102 }
99-
100103 if ( hasVideo ) {
101104 let embedUrl = 'https://www.youtube.com/embed/'
102105 if ( pastedText . includes ( 'youtu.be' ) || pastedText . includes ( 'youtube' ) ) {
@@ -110,19 +113,18 @@ const createMarkdownExtension = () => {
110113 view . dispatch ( view . state . tr . replaceSelectionWith ( node ) )
111114 }
112115 }
116+ } else {
117+ // This is not a media file, just plaintext
118+ bnEditor . markdownToBlocks ( pastedText ) . then ( ( organizedBlocks : any ) => {
119+ const blockInfo = getBlockInfoFromPos ( state . doc , selection . from )
120+ bnEditor . replaceBlocks (
121+ [ blockInfo . node . attrs . id ] ,
122+ // @ts -ignore
123+ organizedBlocks ,
124+ )
125+ BlockUtils . setGroupTypes ( bnEditor . _tiptapEditor , organizedBlocks )
126+ } )
113127 }
114-
115- // bnEditor.markdownToBlocks(pastedText).then((organizedBlocks) => {
116- // const blockInfo = getBlockInfoFromPos(state.doc, selection.from)
117- // console.log(`BLockINfo type: `, blockInfo.node.type.name)
118- // bnEditor.replaceBlocks(
119- // [blockInfo.node.attrs.id],
120- // // @ts -ignore
121- // organizedBlocks,
122- // )
123- // BlockUtils.setGroupTypes(bnEditor._tiptapEditor, organizedBlocks)
124- // })
125-
126128 return true
127129 } ,
128130 } ,
0 commit comments