Skip to content

Commit 9eac29d

Browse files
committed
feat(core): update type parameters listing format
1 parent 3e27a1b commit 9eac29d

10 files changed

+81
-32
lines changed

packages/typedoc-plugin-markdown/src/theme/context/partials/member.declaration.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ export function declaration(
102102
if (this.helpers.useTableFormat('parameters')) {
103103
md.push(this.partials.typeParametersTable(model.typeParameters));
104104
} else {
105-
md.push(this.partials.typeParametersList(model.typeParameters));
105+
md.push(
106+
this.partials.typeParametersList(model.typeParameters, {
107+
headingLevel: options.headingLevel,
108+
}),
109+
);
106110
}
107111
}
108112

packages/typedoc-plugin-markdown/src/theme/context/partials/member.memberWithGroups.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export function memberWithGroups(
4040
if (this.helpers.useTableFormat('parameters')) {
4141
md.push(this.partials.typeParametersTable(model.typeParameters));
4242
} else {
43-
md.push(this.partials.typeParametersList(model.typeParameters));
43+
md.push(
44+
this.partials.typeParametersList(model.typeParameters, {
45+
headingLevel: options.headingLevel,
46+
}),
47+
);
4448
}
4549
}
4650

packages/typedoc-plugin-markdown/src/theme/context/partials/member.signature.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ export function signature(
7676
if (this.helpers.useTableFormat('parameters')) {
7777
md.push(this.partials.typeParametersTable(model.typeParameters));
7878
} else {
79-
md.push(this.partials.typeParametersList(model.typeParameters));
79+
md.push(
80+
this.partials.typeParametersList(model.typeParameters, {
81+
headingLevel: options.headingLevel,
82+
}),
83+
);
8084
}
8185
}
8286

packages/typedoc-plugin-markdown/src/theme/context/partials/member.typeParametersList.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1-
import { bold, italic } from '@plugin/libs/markdown/index.js';
1+
import { heading, italic } from '@plugin/libs/markdown/index.js';
22
import { MarkdownThemeContext } from '@plugin/theme/index.js';
33
import { TypeParameterReflection } from 'typedoc';
44

55
export function typeParametersList(
66
this: MarkdownThemeContext,
77
model: TypeParameterReflection[],
8+
options: { headingLevel: number },
89
): string {
910
const rows: string[] = [];
1011
model?.forEach((typeParameter) => {
1112
const row: string[] = [];
1213

13-
const nameCol: string[] = [bold(typeParameter.name)];
14+
row.push(heading(options.headingLevel + 1, typeParameter.name));
15+
16+
const nameCol: string[] = [];
1417

1518
if (typeParameter.type) {
1619
nameCol.push(
17-
`${italic('extends')} ${this.partials.someType(typeParameter.type)}`,
20+
`${italic('extends')}: ${this.partials.someType(typeParameter.type)}`,
1821
);
1922
}
2023

2124
if (typeParameter.default) {
22-
nameCol.push(`= ${this.partials.someType(typeParameter.default)}`);
25+
nameCol.push(
26+
`${this.i18n.theme_default_type()} ${this.partials.someType(typeParameter.default)}`,
27+
);
2328
}
2429

25-
row.push('• ' + nameCol.join(' '));
30+
row.push(nameCol.join(''));
2631

2732
if (typeParameter.comment) {
2833
row.push(this.partials.comment(typeParameter.comment));
34+
} else {
35+
if (nameCol.join('').length === 0) {
36+
row.push('\\-');
37+
}
2938
}
3039

3140
rows.push(row.join('\n\n'));

packages/typedoc-plugin-markdown/src/theme/context/resources.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ There is no association list partial for properties as these are handled as a st
228228
options: { kind?: ReflectionKind | undefined },
229229
) =>
230230
partials.typeDeclarationTable.apply(context, [model, options]) as string,
231-
typeParametersList: (model: TypeParameterReflection[]) =>
232-
partials.typeParametersList.apply(context, [model]) as string,
231+
typeParametersList: (
232+
model: TypeParameterReflection[],
233+
options: { headingLevel: number },
234+
) => partials.typeParametersList.apply(context, [model, options]) as string,
233235
typeParametersTable: (model: TypeParameterReflection[]) =>
234236
partials.typeParametersTable.apply(context, [model]) as string,
235237
breadcrumbs: () => partials.breadcrumbs.apply(context, []) as string,

packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ export class ClassWithConstructorOverloads {
132132
/**
133133
* Comments for ClassWithTypeParameters
134134
*
135-
* @param A Comments for param A
136135
* @param B Comments for param B
136+
* @param C Comments for param C
137137
*/
138138
export class ClassWithTypeParameters<A, B extends string, C = boolean> {}
139139

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap

+12-6
Original file line numberDiff line numberDiff line change
@@ -1238,15 +1238,21 @@ Comments for ClassWithTypeParameters
12381238
12391239
## Type Parameters
12401240
1241-
• **A**
1241+
### A
12421242
1243-
Comments for param A
1243+
\\-
12441244
1245-
• **B** *extends* \`string\`
1245+
### B
1246+
1247+
*extends*: \`string\`
12461248
12471249
Comments for param B
12481250
1249-
• **C** = \`boolean\`
1251+
### C
1252+
1253+
Default type \`boolean\`
1254+
1255+
Comments for param C
12501256
12511257
## Constructors
12521258
@@ -1269,9 +1275,9 @@ Comments for ClassWithTypeParameters
12691275
12701276
| Type Parameter | Default type | Description |
12711277
| :------ | :------ | :------ |
1272-
| \`A\` | - | Comments for param A |
1278+
| \`A\` | - | - |
12731279
| \`B\` *extends* \`string\` | - | Comments for param B |
1274-
| \`C\` | \`boolean\` | - |
1280+
| \`C\` | \`boolean\` | Comments for param C |
12751281
12761282
## Constructors
12771283

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.function.spec.ts.snap

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Comments for current function 1
2323
2424
#### Type Parameters
2525
26-
• **Value**
26+
##### Value
27+
28+
\\-
2729
2830
#### Parameters
2931
@@ -47,7 +49,9 @@ Comments for iterable arg
4749
4850
### Type Parameters
4951
50-
• **Value**
52+
#### Value
53+
54+
\\-
5155
5256
### Parameters
5357
@@ -154,7 +158,9 @@ Comments for function
154158
155159
### Type Parameters
156160
157-
• **T**
161+
#### T
162+
163+
\\-
158164
159165
### Parameters
160166
@@ -1161,11 +1167,13 @@ Function with type parameters
11611167
11621168
## Type Parameters
11631169
1164-
• **T**
1170+
### T
11651171
11661172
Comments for T
11671173
1168-
• **Item** = \`string\` \\| \`boolean\`
1174+
### Item
1175+
1176+
Default type \`string\` \\| \`boolean\`
11691177
11701178
## Returns
11711179

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.interface.spec.ts.snap

+7-5
Original file line numberDiff line numberDiff line change
@@ -641,22 +641,22 @@ And some more comments
641641
642642
## Type Parameters
643643
644-
• **A**
644+
### A
645645
646646
This is a parameter.
647647
648-
• **B**
648+
### B
649649
650650
Comments for a parameter.
651651
This sentence is on a soft new line.
652652
653-
• **C**
653+
### C
654654
655655
This is a parameter.
656656
657657
Documentation with a double line
658658
659-
• **D**
659+
### D
660660
661661
<p>These are comments with paras</p>
662662
<p>These are comments with paras</p>
@@ -842,7 +842,9 @@ Comments for InterfaceWithTypeParameters
842842
843843
## Type Parameters
844844
845-
• **A**
845+
### A
846+
847+
\\-
846848
847849
## Properties
848850

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap

+15-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Comments for ConditionalType
3737
3838
## Type Parameters
3939
40-
• **T**
40+
### T
41+
42+
\\-
4143
4244
## Source
4345
@@ -429,7 +431,9 @@ Comments for PartialMappedType
429431
430432
## Type Parameters
431433
432-
• **T**
434+
### T
435+
436+
\\-
433437
434438
## Source
435439
@@ -523,7 +527,9 @@ Comments for ReadonlyMapedType
523527
524528
## Type Parameters
525529
526-
• **T**
530+
### T
531+
532+
\\-
527533
528534
## Source
529535
@@ -623,9 +629,13 @@ Comments for TypeWithTypeParams
623629
624630
## Type Parameters
625631
626-
• **T**
632+
### T
633+
634+
\\-
635+
636+
### R
627637
628-
• **R**
638+
\\-
629639
630640
## Source
631641

0 commit comments

Comments
 (0)