Skip to content

Commit c770618

Browse files
authored
Merge branch 'main' into page-group-title
2 parents 5247d61 + c73e07d commit c770618

File tree

8 files changed

+202
-12
lines changed

8 files changed

+202
-12
lines changed

.changeset/beige-falcons-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Fix expandable block anchore resolution

.changeset/ten-parrots-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Increase token max length to fix code not highlighted

packages/gitbook/e2e/pages.spec.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,90 @@ const testCases: TestsCase[] = [
10181018
},
10191019
],
10201020
},
1021+
{
1022+
name: 'Tables',
1023+
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
1024+
tests: [
1025+
{
1026+
name: 'Default table',
1027+
url: 'blocks/tables',
1028+
run: waitForCookiesDialog,
1029+
fullPage: true,
1030+
},
1031+
{
1032+
name: 'Table with straight corners',
1033+
url:
1034+
'blocks/tables' +
1035+
getCustomizationURL({
1036+
styling: {
1037+
corners: CustomizationCorners.Straight,
1038+
},
1039+
}),
1040+
run: waitForCookiesDialog,
1041+
fullPage: true,
1042+
},
1043+
{
1044+
name: 'Table with primary color',
1045+
url:
1046+
'blocks/tables' +
1047+
getCustomizationURL({
1048+
styling: {
1049+
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
1050+
},
1051+
}),
1052+
run: waitForCookiesDialog,
1053+
fullPage: true,
1054+
},
1055+
// Test dark mode for each variant
1056+
...allThemeModes.flatMap((theme) => [
1057+
{
1058+
name: `Table in ${theme} mode`,
1059+
url:
1060+
'blocks/tables' +
1061+
getCustomizationURL({
1062+
themes: {
1063+
default: theme,
1064+
toggeable: false,
1065+
},
1066+
}),
1067+
run: waitForCookiesDialog,
1068+
fullPage: true,
1069+
},
1070+
{
1071+
name: `Table with straight corners in ${theme} mode`,
1072+
url:
1073+
'blocks/tables' +
1074+
getCustomizationURL({
1075+
styling: {
1076+
corners: CustomizationCorners.Straight,
1077+
},
1078+
themes: {
1079+
default: theme,
1080+
toggeable: false,
1081+
},
1082+
}),
1083+
run: waitForCookiesDialog,
1084+
fullPage: true,
1085+
},
1086+
{
1087+
name: `Table with primary color in ${theme} mode`,
1088+
url:
1089+
'blocks/tables' +
1090+
getCustomizationURL({
1091+
styling: {
1092+
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
1093+
},
1094+
themes: {
1095+
default: theme,
1096+
toggeable: false,
1097+
},
1098+
}),
1099+
run: waitForCookiesDialog,
1100+
fullPage: true,
1101+
},
1102+
]),
1103+
],
1104+
},
10211105
];
10221106

10231107
for (const testCase of testCases) {

packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
5050

5151
const lines = highlighter.codeToTokensBase(code, {
5252
lang: langName,
53-
tokenizeMaxLineLength: 120,
53+
tokenizeMaxLineLength: 400,
5454
});
5555

5656
let currentIndex = 0;

packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ export function ViewGrid(props: TableViewProps<DocumentTableViewGrid>) {
3434
<div role="table" className={tcls('flex', 'flex-col')}>
3535
{/* Header */}
3636
{withHeader && (
37-
<div role="rowgroup" className={tcls('flex flex-col', tableWidth)}>
38-
<div role="row" className={tcls('flex', 'w-full', '[&>*+*]:border-l')}>
37+
<div
38+
role="rowgroup"
39+
className={tcls(
40+
tableWidth,
41+
styles.rowGroup,
42+
'straight-corners:rounded-none',
43+
)}
44+
>
45+
<div role="row" className={tcls('flex', 'w-full')}>
3946
{view.columns.map((column) => {
4047
const alignment = getColumnAlignment(block.data.definition[column]);
4148
return (

packages/gitbook/src/components/DocumentView/Table/table.module.css

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,37 @@
2323
}
2424

2525
:global(.dark) .tableWrapper {
26-
@apply border-light/2;
26+
@apply border-tint-50;
27+
}
28+
29+
.columnHeader {
30+
@apply text-sm font-medium py-3 px-4 text-tint-900;
31+
}
32+
33+
:global(.dark) .columnHeader {
34+
@apply text-white;
2735
}
2836

2937
.row {
30-
@apply flex border-dark/3 dark:border-light/2;
38+
@apply flex border-tint-700/2;
3139
}
3240

33-
.row > * + * {
34-
@apply border-l;
41+
:global(.dark) .row {
42+
@apply border-tint-300/3;
43+
}
44+
45+
.rowGroup {
46+
@apply flex flex-col border rounded-lg bg-tint-800/1 border-tint-700/2;
47+
}
48+
49+
:global(.dark) .rowGroup {
50+
@apply bg-tint-300/2 border-tint-300/3;
3551
}
3652

3753
.cell {
38-
@apply flex-1 align-middle border-dark/2 py-2 px-3 text-sm lg:text-base dark:border-light/2;
54+
@apply flex-1 align-middle border-dark/2 py-2 px-4 text-sm;
3955
}
4056

41-
.columnHeader {
42-
@apply align-middle text-left text-base font-medium border-b dark:border-l-light/2 dark:border-b-light/4 py-2 px-3;
57+
:global(.dark) .cell {
58+
@apply border-light/2;
4359
}

packages/gitbook/src/lib/document.test.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'bun:test';
22

3-
import { isNodeEmpty } from './document';
3+
import { getBlockTitle, isNodeEmpty } from './document';
44

55
describe('isNodeEmpty', () => {
66
it('should return true for a document with an empty paragraph', () => {
@@ -54,3 +54,76 @@ describe('isNodeEmpty', () => {
5454
).toEqual(false);
5555
});
5656
});
57+
58+
describe('#getBlockTitle', () => {
59+
it('should return the title of an expandable block', () => {
60+
expect(
61+
getBlockTitle({
62+
object: 'block',
63+
type: 'expandable',
64+
isVoid: true,
65+
data: {},
66+
key: 'OX8znB9VmbgK',
67+
fragments: [
68+
{
69+
object: 'fragment',
70+
nodes: [
71+
{
72+
object: 'block',
73+
type: 'paragraph',
74+
isVoid: false,
75+
data: {},
76+
nodes: [
77+
{
78+
object: 'text',
79+
leaves: [
80+
{
81+
object: 'leaf',
82+
text: 'Title of expandable block',
83+
marks: [],
84+
},
85+
],
86+
key: '7sZdCBHTw6Si',
87+
},
88+
],
89+
key: 'msYtjdwNmiAB',
90+
},
91+
],
92+
key: 'cNhmBygbrP8N',
93+
fragment: 'expandable-title',
94+
type: 'expandable-title',
95+
},
96+
{
97+
object: 'fragment',
98+
nodes: [
99+
{
100+
object: 'block',
101+
type: 'paragraph',
102+
isVoid: false,
103+
data: {},
104+
nodes: [
105+
{
106+
object: 'text',
107+
leaves: [
108+
{
109+
object: 'leaf',
110+
text: 'And content of the expandable',
111+
marks: [],
112+
},
113+
],
114+
key: '0GEghVKyWRBt',
115+
},
116+
],
117+
key: '9iEwdHdZ5y0S',
118+
},
119+
],
120+
key: 'newg71i9Ujjl',
121+
fragment: 'expandable-body',
122+
type: 'expandable-body',
123+
},
124+
],
125+
meta: { id: 'expandable-block' },
126+
}),
127+
).toEqual('Title of expandable block');
128+
});
129+
});

packages/gitbook/src/lib/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function isNodeEmpty(
154154
export function getBlockTitle(block: DocumentBlock): string {
155155
switch (block.type) {
156156
case 'expandable': {
157-
const titleFragment = getNodeFragmentByType(block, 'title');
157+
const titleFragment = getNodeFragmentByType(block, 'expandable-title');
158158
if (titleFragment) {
159159
return getNodeText(titleFragment);
160160
}

0 commit comments

Comments
 (0)