Skip to content

Commit c9dee38

Browse files
committed
Update comment rendering for functions
Resolves #2285
1 parent 2624c28 commit c9dee38

File tree

10 files changed

+72
-14
lines changed

10 files changed

+72
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bug Fixes
1010

11+
- When rendering functions/methods, TypeDoc will now render the comment summary above the parameters/return type,
12+
and any other block tags in the order they are defined in the comment, #2285.
1113
- Comments are no longer removed from classes/interfaces containing call signatures, #2290.
1214

1315
### Thanks!

src/lib/application.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ export class Application extends ChildableComponent<
153153

154154
/**
155155
* Initialize TypeDoc without loading plugins.
156+
*
157+
* @example
158+
* Initialize the application with pretty-printing output disabled.
159+
* ```ts
160+
* const app = new Application();
161+
* app.bootstrap({ pretty: false });
162+
* ```
163+
*
164+
* @param options - Options to set during initialization
156165
*/
157166
bootstrap(options: Partial<TypeDocOptions> = {}): void {
158167
this.options.reset();

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { defaultLayout } from "./layouts/default";
1212
import { index } from "./partials";
1313
import { analytics } from "./partials/analytics";
1414
import { breadcrumb } from "./partials/breadcrumb";
15-
import { comment } from "./partials/comment";
15+
import { comment, commentSummary, commentTags } from "./partials/comment";
1616
import { footer } from "./partials/footer";
1717
import { header } from "./partials/header";
1818
import { hierarchy } from "./partials/hierarchy";
@@ -106,7 +106,10 @@ export class DefaultThemeRenderContext {
106106

107107
analytics = bind(analytics, this);
108108
breadcrumb = bind(breadcrumb, this);
109+
/** @deprecated will be removed in 0.25 */
109110
comment = bind(comment, this);
111+
commentSummary = bind(commentSummary, this);
112+
commentTags = bind(commentTags, this);
110113
footer = bind(footer, this);
111114
header = bind(header, this);
112115
hierarchy = bind(hierarchy, this);

src/lib/output/themes/default/partials/comment.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { JSX, Raw } from "../../../../utils";
33
import { Reflection, ReflectionKind } from "../../../../models";
44
import { camelToTitleCase } from "../../lib";
55

6+
// Note: Comment modifiers are handled in `renderFlags`
7+
68
export function comment({ markdown }: DefaultThemeRenderContext, props: Reflection) {
79
if (!props.comment?.hasVisibleComponent()) return;
810

9-
// Note: Comment modifiers are handled in `renderFlags`
10-
1111
const tags = props.kindOf(ReflectionKind.SomeSignature)
1212
? props.comment.blockTags.filter((tag) => tag.tag !== "@returns")
1313
: props.comment.blockTags;
@@ -24,3 +24,32 @@ export function comment({ markdown }: DefaultThemeRenderContext, props: Reflecti
2424
</div>
2525
);
2626
}
27+
28+
export function commentSummary({ markdown }: DefaultThemeRenderContext, props: Reflection) {
29+
if (!props.comment?.summary.some((part) => part.text)) return;
30+
31+
return (
32+
<div class="tsd-comment tsd-typography">
33+
<Raw html={markdown(props.comment.summary)} />
34+
</div>
35+
);
36+
}
37+
38+
export function commentTags({ markdown }: DefaultThemeRenderContext, props: Reflection) {
39+
if (!props.comment) return;
40+
41+
const tags = props.kindOf(ReflectionKind.SomeSignature)
42+
? props.comment.blockTags.filter((tag) => tag.tag !== "@returns")
43+
: props.comment.blockTags;
44+
45+
return (
46+
<div class="tsd-comment tsd-typography">
47+
{tags.map((item) => (
48+
<>
49+
<h4>{camelToTitleCase(item.tag.substring(1))}</h4>
50+
<Raw html={markdown(item.content)} />
51+
</>
52+
))}
53+
</div>
54+
);
55+
}

src/lib/output/themes/default/partials/member.declaration.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const memberDeclaration = (context: DefaultThemeRenderContext, props: Dec
2424
)}
2525
</div>
2626

27-
{context.comment(props)}
27+
{context.commentSummary(props)}
2828

2929
{hasTypeParameters(props) && context.typeParameters(props.typeParameters)}
3030

@@ -35,6 +35,8 @@ export const memberDeclaration = (context: DefaultThemeRenderContext, props: Dec
3535
</div>
3636
)}
3737

38+
{context.commentTags(props)}
39+
3840
{context.memberSources(props)}
3941
</>
4042
);

src/lib/output/themes/default/partials/member.signature.body.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function memberSignatureBody(
1313
return (
1414
<>
1515
{renderFlags(props.flags, props.comment)}
16-
{context.comment(props)}
16+
{context.commentSummary(props)}
1717

1818
{hasTypeParameters(props) && context.typeParameters(props.typeParameters)}
1919

@@ -36,7 +36,8 @@ export function memberSignatureBody(
3636
</span>
3737
)}
3838
</h5>
39-
{context.comment(item)}
39+
{context.commentSummary(item)}
40+
{context.commentTags(item)}
4041
{item.type instanceof ReflectionType && context.parameter(item.type.declaration)}
4142
</li>
4243
))}
@@ -53,6 +54,9 @@ export function memberSignatureBody(
5354
{props.type instanceof ReflectionType && context.parameter(props.type.declaration)}
5455
</>
5556
)}
57+
58+
{context.commentTags(props)}
59+
5660
{!hideSources && context.memberSources(props)}
5761
</>
5862
);

src/lib/output/themes/default/partials/parameter.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export const parameter = (context: DefaultThemeRenderContext, props: Declaration
4242
<span class="tsd-signature-symbol">{"]: "}</span>
4343
{context.type(props.indexSignature.type)}
4444
</h5>
45-
{context.comment(props.indexSignature)}
45+
{context.commentSummary(props.indexSignature)}
46+
{context.commentTags(props.indexSignature)}
4647
{props.indexSignature.type instanceof ReflectionType &&
4748
context.parameter(props.indexSignature.type.declaration)}
4849
</li>
@@ -75,7 +76,8 @@ export const parameter = (context: DefaultThemeRenderContext, props: Declaration
7576
</span>
7677
{context.type(item.type)}
7778
</h5>
78-
{context.comment(item)}
79+
{context.commentSummary(item)}
80+
{context.commentTags(item)}
7981
{!!item.children && context.parameter(item)}
8082
{item.type instanceof ReflectionType && context.parameter(item.type.declaration)}
8183
</li>
@@ -95,7 +97,8 @@ export const parameter = (context: DefaultThemeRenderContext, props: Declaration
9597
{context.type(item.getSignature.type)}
9698
</h5>
9799

98-
{context.comment(item.getSignature)}
100+
{context.commentSummary(item.getSignature)}
101+
{context.commentTags(item.getSignature)}
99102
</li>
100103
</>
101104
)}
@@ -119,7 +122,8 @@ export const parameter = (context: DefaultThemeRenderContext, props: Declaration
119122
{context.type(item.setSignature.type)}
120123
</h5>
121124

122-
{context.comment(item.setSignature)}
125+
{context.commentSummary(item.setSignature)}
126+
{context.commentTags(item.setSignature)}
123127
</li>
124128
</>
125129
)}

src/lib/output/themes/default/partials/typeParameters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function typeParameters(context: DefaultThemeRenderContext, typeParameter
2727
</>
2828
)}
2929
</h4>
30-
{context.comment(item)}
30+
{context.commentSummary(item)}
31+
{context.commentTags(item)}
3132
</li>
3233
))}
3334
</ul>

src/lib/output/themes/default/templates/reflection.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
1515
return (
1616
<>
1717
{props.model.hasComment() && (
18-
<section class="tsd-panel tsd-comment">{context.comment(props.model)}</section>
18+
<section class="tsd-panel tsd-comment">
19+
{context.commentSummary(props.model)}
20+
{context.commentTags(props.model)}
21+
</section>
1922
)}
2023

2124
{props.model instanceof DeclarationReflection &&
@@ -67,7 +70,8 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
6770
<span class="tsd-signature-symbol">]: </span>
6871
{context.type(props.model.indexSignature.type)}
6972
</div>
70-
{context.comment(props.model.indexSignature)}
73+
{context.commentSummary(props.model.indexSignature)}
74+
{context.commentTags(props.model.indexSignature)}
7175
{props.model.indexSignature?.type instanceof ReflectionType &&
7276
context.parameter(props.model.indexSignature.type.declaration)}
7377
</section>

src/lib/utils/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export abstract class AbstractComponent<O extends ComponentHost>
116116
private _componentOwner: O;
117117

118118
/**
119-
* The name of this component as set by the @Component decorator.
119+
* The name of this component as set by the `@Component` decorator.
120120
*/
121121
public componentName!: string;
122122

0 commit comments

Comments
 (0)