11import { Editor } from "@tiptap/core" ;
2- import { TagParseRule } from "@tiptap/pm/model" ;
2+ import { DOMParser , Fragment , TagParseRule } from "@tiptap/pm/model" ;
33import { NodeView , ViewMutationRecord } from "@tiptap/pm/view" ;
4+ import { mergeParagraphs } from "../../blocks/defaultBlockHelpers.js" ;
45import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js" ;
56import { InlineContentSchema } from "../inlineContent/types.js" ;
67import { StyleSchema } from "../styles/types.js" ;
@@ -87,6 +88,11 @@ export function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor) {
8788export function getParseRules (
8889 config : BlockConfig ,
8990 customParseFunction : CustomBlockImplementation < any , any , any > [ "parse" ] ,
91+ customParseContentFunction : CustomBlockImplementation <
92+ any ,
93+ any ,
94+ any
95+ > [ "parseContent" ] ,
9096) {
9197 const rules : TagParseRule [ ] = [
9298 {
@@ -111,6 +117,37 @@ export function getParseRules(
111117
112118 return props ;
113119 } ,
120+ getContent :
121+ config . content === "inline" || config . content === "none"
122+ ? ( node , schema ) => {
123+ if ( customParseContentFunction ) {
124+ return customParseContentFunction ( {
125+ el : node ,
126+ schema,
127+ } ) ;
128+ }
129+
130+ if ( config . content === "inline" ) {
131+ // Parse the blockquote content as inline content
132+ const element = node as HTMLElement ;
133+
134+ // Clone to avoid modifying the original
135+ const clone = element . cloneNode ( true ) as HTMLElement ;
136+
137+ // Merge multiple paragraphs into one with line breaks
138+ mergeParagraphs ( clone , config . meta ?. code ? "\n" : "<br>" ) ;
139+
140+ // Parse the content directly as a paragraph to extract inline content
141+ const parser = DOMParser . fromSchema ( schema ) ;
142+ const parsed = parser . parse ( clone , {
143+ topNode : schema . nodes . paragraph . create ( ) ,
144+ } ) ;
145+
146+ return parsed . content ;
147+ }
148+ return Fragment . empty ;
149+ }
150+ : undefined ,
114151 } ) ;
115152 }
116153 // getContent(node, schema) {
@@ -147,19 +184,27 @@ export function createBlockSpec<
147184 name : blockConfig . type as T [ "type" ] ,
148185 content : ( blockConfig . content === "inline"
149186 ? "inline*"
150- : "" ) as T [ "content" ] extends "inline" ? "inline*" : "" ,
187+ : blockConfig . content === "none"
188+ ? ""
189+ : blockConfig . content ) as T [ "content" ] extends "inline"
190+ ? "inline*"
191+ : "" ,
151192 group : "blockContent" ,
152- selectable : blockConfig . isSelectable ?? true ,
193+ selectable : blockConfig . meta ?. selectable ?? true ,
153194 isolating : true ,
154195 code : blockConfig . meta ?. code ?? false ,
155- defining : blockConfig . meta ?. defining ?? false ,
196+ defining : blockConfig . meta ?. defining ?? true ,
156197 priority,
157198 addAttributes ( ) {
158199 return propsToAttributes ( blockConfig . propSchema ) ;
159200 } ,
160201
161202 parseHTML ( ) {
162- return getParseRules ( blockConfig , blockImplementation . parse ) ;
203+ return getParseRules (
204+ blockConfig ,
205+ blockImplementation . parse ,
206+ ( blockImplementation as any ) . parseContent ,
207+ ) ;
163208 } ,
164209
165210 renderHTML ( { HTMLAttributes } ) {
0 commit comments