From 394b8b98219dcee17445894634da322b7fe322cc Mon Sep 17 00:00:00 2001 From: - nyankoiscat - Date: Thu, 26 Mar 2026 14:50:39 +0700 Subject: [PATCH] feat: add a first-class ast node for markdown headings Introduce a new `DocHeading` node type so Markdown headings are represented explicitly in the parsed TSDoc tree (instead of being folded into paragraph text). This matches the maintainer guidance in the issue: headings should be regular section members, not a nested section hierarchy. Affected files: DocHeading.ts Signed-off-by: - nyankoiscat - <76279331+Hikkywannafly@users.noreply.github.com> --- tsdoc/src/nodes/DocHeading.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tsdoc/src/nodes/DocHeading.ts diff --git a/tsdoc/src/nodes/DocHeading.ts b/tsdoc/src/nodes/DocHeading.ts new file mode 100644 index 00000000..fae3b6b8 --- /dev/null +++ b/tsdoc/src/nodes/DocHeading.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { DocNodeKind } from './DocNode'; +import { type IDocNodeContainerParameters, DocNodeContainer } from './DocNodeContainer'; + +export type DocHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6; + +export interface IDocHeadingParameters extends IDocNodeContainerParameters { + headingLevel: DocHeadingLevel; +} + +export class DocHeading extends DocNodeContainer { + private readonly _headingLevel: DocHeadingLevel; + + public constructor(parameters: IDocHeadingParameters) { + super(parameters); + + if (!Number.isInteger(parameters.headingLevel) || parameters.headingLevel < 1 || parameters.headingLevel > 6) { + throw new Error('The headingLevel must be an integer between 1 and 6'); + } + + this._headingLevel = parameters.headingLevel; + } + + public get kind(): DocNodeKind.Heading { + return DocNodeKind.Heading; + } + + public get headingLevel(): DocHeadingLevel { + return this._headingLevel; + } +}