From 4f53fcfbeda98ed5166403ddbbf009d38f803021 Mon Sep 17 00:00:00 2001 From: Brett Jephson Date: Tue, 24 Nov 2026 10:27:44 +0000 Subject: [PATCH] Render heading-4 blocks Renders `heading-4` as an `
` with an anchor link, one size step below heading-3, and keeps it out of the page outline. `@gitbook/api` is patched with the new type until a release includes it. RND-12837 Co-Authored-By: Claude Opus 5.5 --- bun.lock | 1 + package.json | 3 ++- .../gitbook/src/components/DocumentView/Block.tsx | 2 ++ .../gitbook/src/components/DocumentView/Heading.tsx | 1 + .../src/components/DocumentView/StepperStep.tsx | 1 + .../gitbook/src/components/DocumentView/spacing.ts | 6 ++++++ .../DocumentView/utils/isBlockOffscreen.ts | 1 + packages/gitbook/src/lib/document-sections.test.ts | 13 ++++++++++--- packages/gitbook/src/lib/document.tsx | 3 ++- packages/gitbook/src/routes/rss.ts | 2 ++ patches/@gitbook%2Fapi@0.214.0.patch | 13 +++++++++++++ 11 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 patches/@gitbook%2Fapi@0.214.0.patch diff --git a/bun.lock b/bun.lock index fc60a88d9..aa358bef7 100644 --- a/bun.lock +++ b/bun.lock @@ -342,6 +342,7 @@ }, "patchedDependencies": { "decode-named-character-reference@1.0.2": "patches/decode-named-character-reference@1.0.2.patch", + "@gitbook/api@0.214.0": "patches/@gitbook%2Fapi@0.214.0.patch", "@shikijs/langs@3.21.0": "patches/@shikijs%2Flangs@3.21.0.patch", "mermaid@11.16.1": "patches/mermaid@11.16.1.patch", "next@16.4.6": "patches/next@16.4.6.patch", diff --git a/package.json b/package.json index 466bd593e..d6b042a32 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@vercel/next@4.4.2": "patches/@vercel%2Fnext@4.4.2.patch", "mermaid@11.16.1": "patches/mermaid@11.16.1.patch", "next@16.4.6": "patches/next@16.4.6.patch", - "@shikijs/langs@3.21.0": "patches/@shikijs%2Flangs@3.21.0.patch" + "@shikijs/langs@3.21.0": "patches/@shikijs%2Flangs@3.21.0.patch", + "@gitbook/api@0.214.0": "patches/@gitbook%2Fapi@0.214.0.patch" } } 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..b64c4693d 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 @lg: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}
`; diff --git a/patches/@gitbook%2Fapi@0.214.0.patch b/patches/@gitbook%2Fapi@0.214.0.patch new file mode 100644 index 000000000..8096bbfe7 --- /dev/null +++ b/patches/@gitbook%2Fapi@0.214.0.patch @@ -0,0 +1,13 @@ +diff --git a/dist/client.d.ts b/dist/client.d.ts +index a55c2aa43b1fe90f2050ef14607a42d4082cccf4..60e8a5fe17844652a1cf7cd368dbeb0c96708a23 100644 +--- a/dist/client.d.ts ++++ b/dist/client.d.ts +@@ -2496,7 +2496,7 @@ export interface DocumentBlockParagraph { + export type DocumentInline = DocumentInlineLink | DocumentInlineEmoji | DocumentInlineIcon | DocumentInlineExpression | DocumentInlineMath | DocumentInlineImage | DocumentInlineAnnotation | DocumentInlineMention | DocumentInlineButton; + export interface DocumentBlockHeading { + object: "block"; +- type: "heading-1" | "heading-2" | "heading-3"; ++ type: "heading-1" | "heading-2" | "heading-3" | "heading-4"; + key?: string; + nodes: (DocumentInline | DocumentText)[]; + data: {