File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,17 @@ export function hasFullWidthBlock(document: JSONDocument): boolean {
30
30
return false ;
31
31
}
32
32
33
+ /**
34
+ * Returns true if the document has more than `limit` blocks and/or inlines that match the `check` predicate.
35
+ */
33
36
export function hasMoreThan (
34
37
document : JSONDocument | DocumentBlock ,
35
38
check : ( block : DocumentBlock | DocumentInline ) => boolean ,
36
39
limit = 1
37
40
) : boolean {
38
41
let count = 0 ;
39
42
40
- function traverse ( node : JSONDocument | DocumentBlock ) : boolean {
43
+ function traverse ( node : JSONDocument | DocumentBlock | DocumentFragment ) : boolean {
41
44
for ( const child of 'nodes' in node ? node . nodes : [ ] ) {
42
45
if ( child . object === 'text' ) continue ;
43
46
@@ -49,6 +52,12 @@ export function hasMoreThan(
49
52
if ( child . object === 'block' && 'nodes' in child ) {
50
53
if ( traverse ( child ) ) return true ;
51
54
}
55
+
56
+ if ( child . object === 'block' && 'fragments' in child ) {
57
+ for ( const fragment of child . fragments ) {
58
+ if ( traverse ( fragment ) ) return true ;
59
+ }
60
+ }
52
61
}
53
62
return false ;
54
63
}
You can’t perform that action at this time.
0 commit comments