Render heading-4 blocks (#4840)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brett Jephson
2026-11-26 11:56:21 +00:00
committed by GitHub
parent a3d37f341a
commit fa871517b2
11 changed files with 33 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Render Heading 4 blocks.
+2 -2
View File
@@ -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"],
+1 -1
View File
@@ -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",
@@ -57,6 +57,7 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
case 'heading-1':
case 'heading-2':
case 'heading-3':
case 'heading-4':
return <Heading {...props} block={block} />;
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 <SkeletonHeading id={id} style={style} />;
case 'paragraph':
@@ -92,4 +92,5 @@ const TAGS: { [type in DocumentBlockHeading['type']]: React.ElementType } = {
'heading-1': 'h2',
'heading-2': 'h3',
'heading-3': 'h4',
'heading-4': 'h5',
};
@@ -27,6 +27,7 @@ export function StepperStep(props: BlockProps<DocumentBlockStepperStep>) {
case 'heading-2':
return '-mt-[calc(1.25rem+1px)]';
case 'heading-3':
case 'heading-4':
return '-mt-[calc(0.50rem+1px)]';
default:
return '';
@@ -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: '',
@@ -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;
@@ -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'),
],
},
],
},
+2 -1
View File
@@ -183,6 +183,7 @@ const TEXT_ONLY_BLOCKS = new Set<DocumentBlock['type']>([
'heading-1',
'heading-2',
'heading-3',
'heading-4',
]);
/**
@@ -270,7 +271,7 @@ export function getBlocksByType<Type extends DocumentBlock['type']>(
* 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);
}
/**
+2
View File
@@ -133,6 +133,8 @@ function getNodeHTML(node: DocumentBlock | DocumentInline | DocumentText): strin
return `<h3>${children}</h3>`;
case 'heading-3':
return `<h4>${children}</h4>`;
case 'heading-4':
return `<h5>${children}</h5>`;
case 'list-unordered':
case 'list-tasks':
return `<ul>${children}</ul>`;