1 | import type { Reflection } from "../reflections/index.js";
|
2 | import { ReflectionSymbolId } from "../reflections/ReflectionSymbolId.js";
|
3 | import type { Serializer, Deserializer, JSONOutput } from "../../serialization/index.js";
|
4 | /**
|
5 | * Represents a parsed piece of a comment.
|
6 | * @category Comments
|
7 | * @see {@link JSONOutput.CommentDisplayPart}
|
8 | */
|
9 | export type CommentDisplayPart =
|
10 | /**
|
11 | * Represents a plain text portion of the comment, may contain markdown
|
12 | */
|
13 | {
|
14 | kind: "text";
|
15 | text: string;
|
16 | }
|
17 | /**
|
18 | * Represents a code block separated out form the plain text entry so
|
19 | * that TypeDoc knows to skip it when parsing relative links and inline tags.
|
20 | **/
|
21 | | {
|
22 | kind: "code";
|
23 | text: string;
|
24 | } | InlineTagDisplayPart | RelativeLinkDisplayPart;
|
25 | /**
|
26 | * Represents an inline tag like `{@link Foo}`
|
27 | *
|
28 | * The `@link`, `@linkcode`, and `@linkplain` tags may have a `target`
|
29 | * property set indicating which reflection/url they link to. They may also
|
30 | * have a `tsLinkText` property which includes the part of the `text` which
|
31 | * TypeScript thinks should be displayed as the link text.
|
32 | * @category Comments
|
33 | * @expand
|
34 | */
|
35 | export interface InlineTagDisplayPart {
|
36 | kind: "inline-tag";
|
37 | tag: `@${string}`;
|
38 | text: string;
|
39 | target?: Reflection | string | ReflectionSymbolId;
|
40 | tsLinkText?: string;
|
41 | }
|
42 | /**
|
43 | * Represents a reference to a path relative to where the comment resides.
|
44 | * This is used to detect and copy relative image links.
|
45 | *
|
46 | * Use {@link FileRegistry} to determine what path on disc this refers to.
|
47 | *
|
48 | * This is used for relative links within comments/documents.
|
49 | * It is used to mark pieces of text which need to be replaced
|
50 | * to make links work properly.
|
51 | * @category Comments
|
52 | * @expand
|
53 | */
|
54 | export interface RelativeLinkDisplayPart {
|
55 | kind: "relative-link";
|
56 | /**
|
57 | * The original relative text from the parsed comment.
|
58 | */
|
59 | text: string;
|
60 | /**
|
61 | * A link to either some document outside of the project or a reflection.
|
62 | * This may be `undefined` if the relative path does not exist.
|
63 | */
|
64 | target: number | undefined;
|
65 | /**
|
66 | * Anchor within the target page, validated after rendering if possible
|
67 | */
|
68 | targetAnchor: string | undefined;
|
69 | }
|
70 | /**
|
71 | * A model that represents a single TypeDoc comment tag.
|
72 | *
|
73 | * Tags are stored in the {@link Comment.blockTags} property.
|
74 | * @category Comments
|
75 | */
|
76 | export declare class CommentTag {
|
77 | /**
|
78 | * The name of this tag, e.g. `@returns`, `@example`
|
79 | */
|
80 | tag: `@${string}`;
|
81 | /**
|
82 | * Some tags, (`@typedef`, `@param`, `@property`, etc.) may have a user defined identifier associated with them.
|
83 | * If this tag is one of those, it will be parsed out and included here.
|
84 | */
|
85 | name?: string;
|
86 | /**
|
87 | * The actual body text of this tag.
|
88 | */
|
89 | content: CommentDisplayPart[];
|
90 | /**
|
91 | * A flag which may be set by plugins to prevent TypeDoc from rendering this tag, if the plugin provides
|
92 | * custom rendering. Note: This flag is **not** serialized, it is expected to be set just before the comment
|
93 | * is rendered.
|
94 | */
|
95 | skipRendering: boolean;
|
96 | /**
|
97 | * Create a new CommentTag instance.
|
98 | */
|
99 | constructor(tag: `string}`, text: CommentDisplayPart[]);
{ |
100 | /**
|
101 | * Checks if this block tag is roughly equal to the other tag.
|
102 | * This isn't exactly equal, but just "roughly equal" by the tag
|
103 | * text.
|
104 | */
|
105 | similarTo(other: CommentTag): boolean;
|
106 | clone(): CommentTag;
|
107 | toObject(serializer: Serializer): JSONOutput.CommentTag;
|
108 | fromObject(de: Deserializer, obj: JSONOutput.CommentTag): void;
|
109 | }
|
110 | /**
|
111 | * A model that represents a comment.
|
112 | *
|
113 | * Instances of this model are created by the CommentPlugin. You can retrieve comments
|
114 | * through the { DeclarationReflection.comment} property.
|
115 | * Comments
|
116 | */
|
117 | export declare class Comment {
|
118 | /**
|
119 | * Debugging utility for combining parts into a simple string. Not suitable for
|
120 | * rendering, but can be useful in tests.
|
121 | */
|
122 | static combineDisplayParts(parts: readonly CommentDisplayPart[] | undefined): string;
|
123 | /**
|
124 | * Helper utility to clone {@link Comment.summary} or {@link CommentTag.content}
|
125 | */
|
126 | static cloneDisplayParts(parts: readonly CommentDisplayPart[]): CommentDisplayPart[];
|
127 | static serializeDisplayParts(serializer: Serializer, parts: CommentDisplayPart[]): JSONOutput.CommentDisplayPart[];
|
128 | /** @hidden no point in showing this signature in api docs */
|
129 | static serializeDisplayParts(serializer: Serializer, parts: CommentDisplayPart[] | undefined): JSONOutput.CommentDisplayPart[] | undefined;
|
130 | static deserializeDisplayParts(de: Deserializer, parts: JSONOutput.CommentDisplayPart[]): CommentDisplayPart[];
|
131 | /**
|
132 | * Splits the provided parts into a header (first line, as a string)
|
133 | * and body (remaining lines). If the header line contains inline tags
|
134 | * they will be serialized to a string.
|
135 | */
|
136 | static splitPartsToHeaderAndBody(parts: readonly CommentDisplayPart[]): {
|
137 | header: string;
|
138 | body: CommentDisplayPart[];
|
139 | };
|
140 | /**
|
141 | * The content of the comment which is not associated with a block tag.
|
142 | */
|
143 | summary: CommentDisplayPart[];
|
144 | /**
|
145 | * All associated block level tags.
|
146 | */
|
147 | blockTags: CommentTag[];
|
148 | /**
|
149 | * All modifier tags present on the comment, e.g. `@alpha`, `@beta`.
|
150 | */
|
151 | modifierTags: Set<`@${string}`>;
|
152 | /**
|
153 | * Label associated with this reflection, if any (https://tsdoc.org/pages/tags/label/)
|
154 | */
|
155 | label?: string;
|
156 | /**
|
157 | * Full path to the file where this comment originated from, if any.
|
158 | * This field will not be serialized, so will not be present when handling JSON-revived reflections.
|
159 | *
|
160 | * Note: This field is non-enumerable to make testing comment contents with `deepEqual` easier.
|
161 | */
|
162 | sourcePath?: string;
|
163 | /**
|
164 | * Internal discovery ID used to prevent symbol comments from
|
165 | * being duplicated on signatures. Only set when the comment was created
|
166 | * from a `ts.CommentRange`.
|
167 | * @internal
|
168 | */
|
169 | discoveryId?: number;
|
170 | /**
|
171 | * If the comment was inherited from a different "parent" declaration
|
172 | * (see #2545), then it is desirable to know this as any `@param` tags
|
173 | * which do not apply should not cause warnings. This is not serialized,
|
174 | * and only set when the comment was created from a `ts.CommentRange`.
|
175 | */
|
176 | inheritedFromParentDeclaration?: boolean;
|
177 | /**
|
178 | * Creates a new Comment instance.
|
179 | */
|
180 | constructor(summary?: CommentDisplayPart[], blockTags?: CommentTag[], modifierTags?: Set<`string}`>);
{ |
181 | /**
|
182 | * Gets either the `@summary` tag, or a short version of the comment summary
|
183 | * section for rendering in module/namespace pages.
|
184 | */
|
185 | getShortSummary(useFirstParagraph: boolean): readonly CommentDisplayPart[];
|
186 | /**
|
187 | * Checks if this comment is roughly equal to the other comment.
|
188 | * This isn't exactly equal, but just "roughly equal" by the comment
|
189 | * text.
|
190 | */
|
191 | similarTo(other: Comment): boolean;
|
192 | /**
|
193 | * Create a deep clone of this comment.
|
194 | */
|
195 | clone(): Comment;
|
196 | /**
|
197 | * Returns true if this comment is completely empty.
|
198 | * @internal
|
199 | */
|
200 | isEmpty(): boolean;
|
201 | /**
|
202 | * Has this comment a visible component?
|
203 | *
|
204 | * @returns TRUE when this comment has a visible component.
|
205 | */
|
206 | hasVisibleComponent(): boolean;
|
207 | /**
|
208 | * Test whether this comment contains a tag with the given name.
|
209 | *
|
210 | * @param tagName The name of the tag to look for.
|
211 | * @returns TRUE when this comment contains a tag with the given name, otherwise FALSE.
|
212 | */
|
213 | hasModifier(tagName: `string}`): boolean;
{ |
214 | removeModifier(tagName: `string}`): void;
{ |
215 | /**
|
216 | * Return the first tag with the given name.
|
217 | *
|
218 | * @param tagName The name of the tag to look for.
|
219 | * @returns The found tag or undefined.
|
220 | */
|
221 | getTag(tagName: `string}`): CommentTag | undefined;
{ |
222 | /**
|
223 | * Get all tags with the given tag name.
|
224 | */
|
225 | getTags(tagName: `string}`): CommentTag[];
{ |
226 | getIdentifiedTag(identifier: string, tagName: ` {string}`): CommentTag | undefined;
|
227 | /**
|
228 | * Removes all block tags with the given tag name from the comment.
|
229 | * @param tagName
|
230 | */
|
231 | removeTags(tagName: `string}`): void;
{ |
232 | toObject(serializer: Serializer): JSONOutput.Comment;
|
233 | fromObject(de: Deserializer, obj: JSONOutput.Comment): void;
|
234 | }
|