Skip to content

Commit 54a797a

Browse files
authored
Nested list support (#2562)
1 parent a78c1ec commit 54a797a

File tree

11 files changed

+281
-269
lines changed

11 files changed

+281
-269
lines changed

packages/gitbook/src/components/DocumentView/Block.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import { Heading } from './Heading';
2222
import { Hint } from './Hint';
2323
import { Images } from './Images';
2424
import { IntegrationBlock } from './Integration';
25+
import { List } from './List';
2526
import { ListItem } from './ListItem';
26-
import { ListOrdered } from './ListOrdered';
27-
import { ListTasks } from './ListTasks';
28-
import { ListUnordered } from './ListUnordered';
2927
import { BlockMath } from './Math';
3028
import { OpenAPI } from './OpenAPI';
3129
import { Paragraph } from './Paragraph';
@@ -65,11 +63,9 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
6563
case 'heading-3':
6664
return <Heading {...props} block={block} />;
6765
case 'list-ordered':
68-
return <ListOrdered {...props} block={block} />;
6966
case 'list-unordered':
70-
return <ListUnordered {...props} block={block} />;
7167
case 'list-tasks':
72-
return <ListTasks {...props} block={block} />;
68+
return <List {...props} block={block} />;
7369
case 'list-item':
7470
return <ListItem {...props} block={block} />;
7571
case 'code':
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
DocumentBlockListOrdered,
3+
DocumentBlockListTasks,
4+
DocumentBlockListUnordered,
5+
} from '@gitbook/api';
6+
import assertNever from 'assert-never';
7+
8+
import { BlockProps } from './Block';
9+
import { Blocks } from './Blocks';
10+
11+
export function List(
12+
props: BlockProps<
13+
DocumentBlockListUnordered | DocumentBlockListOrdered | DocumentBlockListTasks
14+
>,
15+
) {
16+
const { block, style, ancestorBlocks, ...contextProps } = props;
17+
18+
return (
19+
<Blocks
20+
{...contextProps}
21+
tag={getListTag(block.type)}
22+
nodes={block.nodes}
23+
ancestorBlocks={[...ancestorBlocks, block]}
24+
style={['space-y-2', style]}
25+
/>
26+
);
27+
}
28+
29+
function getListTag(
30+
type:
31+
| DocumentBlockListUnordered['type']
32+
| DocumentBlockListOrdered['type']
33+
| DocumentBlockListTasks['type'],
34+
) {
35+
switch (type) {
36+
case 'list-ordered':
37+
return 'ol';
38+
case 'list-unordered':
39+
case 'list-tasks':
40+
return 'ul';
41+
default:
42+
assertNever(type);
43+
}
44+
}

packages/gitbook/src/components/DocumentView/ListItem.module.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)