diff --git a/.changeset/empty-days-add.md b/.changeset/empty-days-add.md new file mode 100644 index 000000000..e233fb71a --- /dev/null +++ b/.changeset/empty-days-add.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Render Heading 4 blocks. diff --git a/bun.lock b/bun.lock index 9b8a717b7..eaad40191 100644 --- a/bun.lock +++ b/bun.lock @@ -357,7 +357,7 @@ }, "catalog": { "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.214.0", + "@gitbook/api": "0.215.0", "@scalar/api-client-react": "^1.3.46", "@tsconfig/node20": "^20.1.6", "@tsconfig/strictest": "^2.0.6", @@ -725,7 +725,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@7.2.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "7.2.0" } }, "sha512-6639htZMjEkwskf3J+e6/iar+4cTNM9qhoWuRfj9F3eJD6r7iCzV1SWnQr2Mdv0QT0suuqU8BoJCZUyCtP9R4Q=="], - "@gitbook/api": ["@gitbook/api@0.214.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-rNmnQIgg0mhdknDMc2/3dhoKk+XmCP1P5qTrhazI458WsqkPCSMV2o7B6cJADUzs9svH78y5z7bSRzrrOMmV4g=="], + "@gitbook/api": ["@gitbook/api@0.215.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-y9Xx3Xmls5A6C0PX24VYUdcb1CSFgjwlrnkPagq5ZpAYsDAx4xMu0SNiF/aoaqgJdeHlR+jtQkUx/5y0osAvGA=="], "@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"], diff --git a/package.json b/package.json index 466bd593e..6c7128d29 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@tsconfig/strictest": "^2.0.6", "@tsconfig/node20": "^20.1.6", "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.214.0", + "@gitbook/api": "0.215.0", "@scalar/api-client-react": "^1.3.46", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", diff --git a/packages/gitbook/src/components/DocumentView/Block.tsx b/packages/gitbook/src/components/DocumentView/Block.tsx index 1d5f20805..074fa53c1 100644 --- a/packages/gitbook/src/components/DocumentView/Block.tsx +++ b/packages/gitbook/src/components/DocumentView/Block.tsx @@ -57,6 +57,7 @@ export function Block(props: BlockProps) { case 'heading-1': case 'heading-2': case 'heading-3': + case 'heading-4': return ; case 'list-ordered': case 'list-unordered': @@ -140,6 +141,7 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue } case 'heading-1': case 'heading-2': case 'heading-3': + case 'heading-4': case 'file': return ; case 'paragraph': diff --git a/packages/gitbook/src/components/DocumentView/Heading.tsx b/packages/gitbook/src/components/DocumentView/Heading.tsx index 28eb52970..b42ef8705 100644 --- a/packages/gitbook/src/components/DocumentView/Heading.tsx +++ b/packages/gitbook/src/components/DocumentView/Heading.tsx @@ -92,4 +92,5 @@ const TAGS: { [type in DocumentBlockHeading['type']]: React.ElementType } = { 'heading-1': 'h2', 'heading-2': 'h3', 'heading-3': 'h4', + 'heading-4': 'h5', }; diff --git a/packages/gitbook/src/components/DocumentView/StepperStep.tsx b/packages/gitbook/src/components/DocumentView/StepperStep.tsx index b56bba50b..173402bc4 100644 --- a/packages/gitbook/src/components/DocumentView/StepperStep.tsx +++ b/packages/gitbook/src/components/DocumentView/StepperStep.tsx @@ -27,6 +27,7 @@ export function StepperStep(props: BlockProps) { case 'heading-2': return '-mt-[calc(1.25rem+1px)]'; case 'heading-3': + case 'heading-4': return '-mt-[calc(0.50rem+1px)]'; default: return ''; diff --git a/packages/gitbook/src/components/DocumentView/spacing.ts b/packages/gitbook/src/components/DocumentView/spacing.ts index 097a30e64..832a200a0 100644 --- a/packages/gitbook/src/components/DocumentView/spacing.ts +++ b/packages/gitbook/src/components/DocumentView/spacing.ts @@ -35,6 +35,12 @@ export function getBlockTextStyle(block: DocumentBlock): { lineHeight: 'leading-snug', marginTop: 'column-first-of-type:pt-0 pt-[0.5em]', }; + case 'heading-4': + return { + textSize: 'text-base @xs:text-lg font-semibold', + lineHeight: 'leading-snug', + marginTop: 'column-first-of-type:pt-0 pt-[0.5em]', + }; case 'divider': return { textSize: '', diff --git a/packages/gitbook/src/components/DocumentView/utils/isBlockOffscreen.ts b/packages/gitbook/src/components/DocumentView/utils/isBlockOffscreen.ts index e3b5ec495..123e94f0b 100644 --- a/packages/gitbook/src/components/DocumentView/utils/isBlockOffscreen.ts +++ b/packages/gitbook/src/components/DocumentView/utils/isBlockOffscreen.ts @@ -83,6 +83,7 @@ const getBlockHeight = memoize((block: DocumentBlock | undefined): number => { case 'heading-2': return 50; case 'heading-3': + case 'heading-4': return 40; case 'paragraph': return 30; diff --git a/packages/gitbook/src/lib/document-sections.test.ts b/packages/gitbook/src/lib/document-sections.test.ts index 88d0ba48f..67a3670b6 100644 --- a/packages/gitbook/src/lib/document-sections.test.ts +++ b/packages/gitbook/src/lib/document-sections.test.ts @@ -237,8 +237,11 @@ describe('getDocumentSections', () => { ]); }); - it('nests heading-3 under the heading before it', async () => { - const heading = (type: 'heading-1' | 'heading-2' | 'heading-3', id: string) => ({ + it('nests heading-3 under the heading before it and leaves heading-4 out', async () => { + const heading = ( + type: 'heading-1' | 'heading-2' | 'heading-3' | 'heading-4', + id: string + ) => ({ object: 'block' as const, type, data: {}, @@ -261,6 +264,7 @@ describe('getDocumentSections', () => { heading('heading-3', 'h3-under-h1'), heading('heading-2', 'h2'), heading('heading-3', 'h3-under-h1-h2'), + heading('heading-4', 'h4-not-in-outline'), { object: 'block', type: 'stepper', @@ -272,7 +276,10 @@ describe('getDocumentSections', () => { type: 'stepper-step', data: {}, isVoid: false, - nodes: [heading('heading-3', 'h3-in-stepper')], + nodes: [ + heading('heading-3', 'h3-in-stepper'), + heading('heading-4', 'h4-in-stepper'), + ], }, ], }, diff --git a/packages/gitbook/src/lib/document.tsx b/packages/gitbook/src/lib/document.tsx index 7b3c08f2e..a3d7418dd 100644 --- a/packages/gitbook/src/lib/document.tsx +++ b/packages/gitbook/src/lib/document.tsx @@ -183,6 +183,7 @@ const TEXT_ONLY_BLOCKS = new Set([ 'heading-1', 'heading-2', 'heading-3', + 'heading-4', ]); /** @@ -270,7 +271,7 @@ export function getBlocksByType( * Check if a block is a heading block. */ export function isHeadingBlock(block: DocumentBlock): block is DocumentBlockHeading { - return ['heading-1', 'heading-2', 'heading-3'].includes(block.type); + return ['heading-1', 'heading-2', 'heading-3', 'heading-4'].includes(block.type); } /** diff --git a/packages/gitbook/src/routes/rss.ts b/packages/gitbook/src/routes/rss.ts index 08c69ac41..d104ed99a 100644 --- a/packages/gitbook/src/routes/rss.ts +++ b/packages/gitbook/src/routes/rss.ts @@ -133,6 +133,8 @@ function getNodeHTML(node: DocumentBlock | DocumentInline | DocumentText): strin return `

${children}

`; case 'heading-3': return `

${children}

`; + case 'heading-4': + return `
${children}
`; case 'list-unordered': case 'list-tasks': return `
    ${children}
`;