Skip to content

Commit 16712a4

Browse files
committed
fix(core): fix display of index descriptions in tables
1 parent 4fa4093 commit 16712a4

File tree

10 files changed

+313
-169
lines changed

10 files changed

+313
-169
lines changed

.changeset/yellow-beds-smile.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
"typedoc-plugin-markdown": patch
2+
'typedoc-plugin-markdown': patch
33
---
44

55
- Remove superfluous quotes from prop names (#619)
6+
- Fix display of index descriptions in tables (#619)

packages/typedoc-plugin-markdown/src/theme/resources/helpers/get-declaration-comment.ts

-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ export function getDeclarationComment(model: DeclarationReflection) {
44
if (model.signatures?.length) {
55
return model.signatures[0].comment;
66
}
7-
if ((model.type as any)?.declaration?.signatures?.length) {
8-
return (model.type as any)?.declaration.signatures[0].comment;
9-
}
107
return model.comment;
118
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ There is no association list partial for properties as these are handled as a st
596596
export const helpers = (context: MarkdownThemeContext) => {
597597
return {
598598
getDeclarationComment: (model: DeclarationReflection) =>
599-
getDeclarationComment.apply(context, [model]) as any,
599+
getDeclarationComment.apply(context, [model]) as Comment | undefined,
600600
getDeclarationType: (model: DeclarationReflection) =>
601601
getDeclarationType.apply(context, [model]) as SomeType | undefined,
602602
getFlattenedDeclarations: (

packages/typedoc-plugin-markdown/src/theme/resources/partials/member.reflectionIndex.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ function getTable(
110110
const comment = context.helpers.getDeclarationComment(child);
111111

112112
if (comment?.summary?.length) {
113-
row.push(context.partials.commentParts(comment.summary)?.split('\n')[0]);
113+
row.push(
114+
context.partials
115+
.commentParts(comment.summary)
116+
?.split('\n\n')[0]
117+
.replace(/\n/g, ' '),
118+
);
114119
} else {
115120
row.push('-');
116121
}

packages/typedoc-plugin-markdown/test/fixtures/config.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ const config: Record<string, Fixture> = {
7676
only: false,
7777
entryPoints: '/groups/**/*.ts',
7878
commonOptions: {
79-
plugin: [path.join(__dirname, 'custom-plugins', 'navigation-plugin.mjs')],
79+
plugin: [
80+
path.join(__dirname, 'custom-plugins', 'stub-groups-theme.mjs'),
81+
path.join(__dirname, 'custom-plugins', 'navigation-plugin.mjs'),
82+
],
83+
theme: 'stub-groups',
8084
disableSources: true,
8185
entryFileName: 'index.md',
8286
},
@@ -89,7 +93,13 @@ const config: Record<string, Fixture> = {
8993
},
9094
{
9195
readme: 'none',
92-
membersWithOwnFile: ['Class', 'Interface', 'Enum'],
96+
membersWithOwnFile: [
97+
'Class',
98+
'Interface',
99+
'Enum',
100+
'TypeAlias',
101+
'Function',
102+
],
93103
excludeGroups: true,
94104
useHTMLAnchors: true,
95105
indexFormat: 'table',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown';
3+
4+
/**
5+
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
6+
*/
7+
export function load(app) {
8+
app.renderer.defineTheme('stub-groups', StubPartialsTheme);
9+
}
10+
11+
class StubPartialsTheme extends MarkdownTheme {
12+
/**
13+
* @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page
14+
*/
15+
getRenderContext(page) {
16+
return new MyMarkdownThemeContext(this, page, this.application.options);
17+
}
18+
}
19+
20+
class MyMarkdownThemeContext extends MarkdownThemeContext {
21+
partials = {
22+
...this.partials,
23+
declaration: () => {
24+
return `_DECLARATION_MEMBER_PARTIAL_`;
25+
},
26+
signature: () => {
27+
return `_SIGNATURE_MEMBER_PARTIAL_`;
28+
},
29+
};
30+
}

packages/typedoc-plugin-markdown/test/fixtures/src/groups/basic.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,46 @@
33
*
44
* @module
55
*/
6+
7+
/**
8+
* Interface A comments line 1
9+
* and comments on a soft line.
10+
*
11+
* Comments on double new line.
12+
*/
613
export interface InterfaceA {
714
propA: string;
815
propB: string;
916
}
17+
18+
/**
19+
* InterfaceB function.
20+
*/
1021
export interface InterfaceB {}
22+
/**
23+
* EnumA function.
24+
*/
1125
export enum EnumA {}
1226
export enum EnumB {}
27+
/**
28+
* ClassA function.
29+
*/
1330
export class ClassA {}
1431
export class ClassB {}
32+
/**
33+
* TypeA function.
34+
*/
1535
export type TypeA = string;
16-
export type TypeB = string;
36+
/**
37+
* TypeB function.
38+
*
39+
* @param str - A string to tokenize.
40+
* @param offset - Initial offset. Used when composing lexers.
41+
*/
42+
export type TypeB = (str: string, offset?: number) => any;
43+
/**
44+
* functionA function.
45+
*/
46+
export function functionA() {}
47+
export const variableA = '';
48+
export const variableB = '';

0 commit comments

Comments
 (0)