angular/adev/shared-docs/pipeline/api-gen/rendering/rendering.mts
Shuaib Hasan Akib 8bdd98ef41 fix(docs-infra): prevent duplicate description rendering for block API entries
Block entries (@if, @defer, @for,@let, @switch) were falling back to the generic
DocsReference template, causing the description to appear twice - once in
the header section and once in the main content area.

This commit adds a dedicated rendering path for block entries:
- Creates BlockEntryRenderable type and associated transforms
- Adds BlockReference template that uses RawHtml directly
- Modifies HeaderApi to accept hideDescription prop
- Updates processing and rendering pipelines to handle blocks

The fix ensures block documentation displays only one description section
while preserving the existing behavior for all other API entry types.

Update adev/shared-docs/pipeline/api-gen/rendering/transforms/block-transforms.mts

Co-authored-by: Matthieu Riegler <kyro38@gmail.com>
2026-01-12 13:37:54 -08:00

70 lines
2.4 KiB
TypeScript

/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {render} from 'preact-render-to-string';
import {
isClassEntry,
isCliEntry,
isConstantEntry,
isDecoratorEntry,
isEnumEntry,
isFunctionEntry,
isInitializerApiFunctionEntry,
isInterfaceEntry,
isTypeAliasEntry,
isBlockEntry,
} from './entities/categorization.mjs';
import {CliCommandRenderable, DocEntryRenderable} from './entities/renderables.mjs';
import {ClassReference} from './templates/class-reference';
import {CliCommandReference} from './templates/cli-reference';
import {ConstantReference} from './templates/constant-reference';
import {DocsReference} from './templates/docs-reference';
import {EnumReference} from './templates/enum-reference';
import {FunctionReference} from './templates/function-reference';
import {InitializerApiFunction} from './templates/initializer-api-function';
import {TypeAliasReference} from './templates/type-alias-reference';
import {DecoratorReference} from './templates/decorator-reference';
import {setCurrentSymbol} from './symbol-context.mjs';
import {BlockReference} from './templates/block-reference';
/** Given a doc entry, get the transformed version of the entry for rendering. */
export function renderEntry(renderable: DocEntryRenderable | CliCommandRenderable): string {
setCurrentSymbol(renderable.name);
if (isCliEntry(renderable)) {
return render(CliCommandReference(renderable));
}
if (isClassEntry(renderable) || isInterfaceEntry(renderable)) {
return render(ClassReference(renderable));
}
if (isDecoratorEntry(renderable)) {
return render(DecoratorReference(renderable));
}
if (isConstantEntry(renderable)) {
return render(ConstantReference(renderable));
}
if (isEnumEntry(renderable)) {
return render(EnumReference(renderable));
}
if (isFunctionEntry(renderable)) {
return render(FunctionReference(renderable));
}
if (isTypeAliasEntry(renderable)) {
return render(TypeAliasReference(renderable));
}
if (isInitializerApiFunctionEntry(renderable)) {
return render(InitializerApiFunction(renderable));
}
if (isBlockEntry(renderable)) {
return render(BlockReference(renderable));
}
// Fall back rendering nothing while in development.
return render(DocsReference(renderable));
}