Skip to content

Commit 667a0cb

Browse files
committed
Code review
1 parent eebd60a commit 667a0cb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/gitbook/src/lib/document.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ export function hasFullWidthBlock(document: JSONDocument): boolean {
3030
return false;
3131
}
3232

33+
/**
34+
* Returns true if the document has more than `limit` blocks and/or inlines that match the `check` predicate.
35+
*/
3336
export function hasMoreThan(
3437
document: JSONDocument | DocumentBlock,
3538
check: (block: DocumentBlock | DocumentInline) => boolean,
3639
limit = 1
3740
): boolean {
3841
let count = 0;
3942

40-
function traverse(node: JSONDocument | DocumentBlock): boolean {
43+
function traverse(node: JSONDocument | DocumentBlock | DocumentFragment): boolean {
4144
for (const child of 'nodes' in node ? node.nodes : []) {
4245
if (child.object === 'text') continue;
4346

@@ -49,6 +52,12 @@ export function hasMoreThan(
4952
if (child.object === 'block' && 'nodes' in child) {
5053
if (traverse(child)) return true;
5154
}
55+
56+
if (child.object === 'block' && 'fragments' in child) {
57+
for (const fragment of child.fragments) {
58+
if (traverse(fragment)) return true;
59+
}
60+
}
5261
}
5362
return false;
5463
}

0 commit comments

Comments
 (0)