Skip to content

Commit 3e0d41a

Browse files
committed
fix(core): correctly handle anchor resolutions with table formats
1 parent 5bd12c8 commit 3e0d41a

File tree

14 files changed

+96
-59
lines changed

14 files changed

+96
-59
lines changed

.changeset/famous-forks-float.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': patch
3+
---
4+
5+
- Correctly handle anchor resolutions with table formats.

docs/pages/docs/options/display-options.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ As a work around the [`@link`](https://typedoc.org/tags/link/) tag can be be use
8282

8383
> Accepts a boolean value. Defaults to `false`.
8484
85-
By default objects inside declarations are collapsed to preserve space and improve readability.
85+
By default when objects have associated documentation, object declarations are collapsed to preserve space and improve readability.
8686

8787
This option should be set when a full object representation is preferred.
8888

docs/pages/docs/options/utility-options.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ This option can be used for engines that require the preservation of anchor link
155155

156156
<Callout emoji="💡">Change specific text placeholders in the template.</Callout>
157157

158-
>
158+
> Accepts a key/value object.
159159
160160
Customizes the page titles for index, module, and member pages in the documentation.
161161

packages/typedoc-plugin-markdown/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"prebuild": "rm -rf dist && prebuild-options && tsx ./.scripts/prebuild",
1616
"build": "tsc && tsc-alias",
1717
"build-and-run": "npm run build && npm run fixtures",
18-
"fixtures": "node test/__scripts__/build-fixtures.mjs -c test/fixtures/config.mjs",
18+
"fixtures": "rm -rf ./test/fixtures/out && node test/__scripts__/build-fixtures.mjs -c test/fixtures/config.mjs",
1919
"validate": "node test/__scripts__/lint/lint.md.mjs && tsx test/__scripts__/lint/lint.mdx.mjs",
2020
"pretest": "npm run fixtures -- -isCI",
2121
"test": "npm run validate && jest",

packages/typedoc-plugin-markdown/src/theme/base/url-builder.ts

+32-19
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,19 @@ export class UrlBuilder {
542542
anchorParts.unshift(`${anchorPrefix}`);
543543
}
544544

545-
reflection.url = containerUrl + '#' + anchorParts.join('');
545+
reflection.url =
546+
reflection.kind === ReflectionKind.TypeLiteral
547+
? containerUrl
548+
: containerUrl + '#' + anchorParts.join('');
546549
reflection.anchor = anchorParts.join('');
547550
reflection.hasOwnDocument = false;
548-
549-
if (
550-
this.options.getValue('outputFileStrategy') ===
551-
OutputFileStrategy.Members
552-
) {
553-
reflection.traverse((child) => {
554-
this.applyAnchorUrl(child as DeclarationReflection, containerUrl);
555-
});
556-
}
551+
}
552+
if (
553+
this.options.getValue('outputFileStrategy') === OutputFileStrategy.Members
554+
) {
555+
reflection.traverse((child) => {
556+
this.applyAnchorUrl(child as DeclarationReflection, containerUrl);
557+
});
557558
}
558559
}
559560

@@ -578,21 +579,33 @@ export class UrlBuilder {
578579
if (!htmlTableAnchors) {
579580
if (
580581
(reflection.kind === ReflectionKind.Property &&
581-
this.options.getValue('propertiesFormat').toLowerCase() ===
582-
'table') ||
582+
this.options
583+
.getValue('propertiesFormat')
584+
.toLowerCase()
585+
.includes('table')) ||
583586
(reflection.kind === ReflectionKind.Property &&
584-
this.options.getValue('typeDeclarationFormat').toLowerCase() ===
585-
'table') ||
587+
reflection.parent?.kind === ReflectionKind.TypeLiteral &&
588+
this.options
589+
.getValue('typeDeclarationFormat')
590+
.toLowerCase()
591+
.includes('table')) ||
586592
(reflection.kind === ReflectionKind.Property &&
587593
reflection.parent?.kind === ReflectionKind.Class &&
588-
this.options.getValue('classPropertiesFormat').toLowerCase() ===
589-
'table') ||
594+
this.options
595+
.getValue('classPropertiesFormat')
596+
.toLowerCase()
597+
.includes('table')) ||
590598
(reflection.kind === ReflectionKind.Property &&
591599
reflection.parent?.kind === ReflectionKind.Interface &&
592-
this.options.getValue('interfacePropertiesFormat').toLowerCase() ===
593-
'table') ||
600+
this.options
601+
.getValue('interfacePropertiesFormat')
602+
.toLowerCase()
603+
.includes('table')) ||
594604
(reflection.kind === ReflectionKind.EnumMember &&
595-
this.options.getValue('enumMembersFormat').toLowerCase() === 'table')
605+
this.options
606+
.getValue('enumMembersFormat')
607+
.toLowerCase()
608+
.includes('table'))
596609
) {
597610
return null;
598611
}

packages/typedoc-plugin-markdown/src/theme/context/helpers/get-comment-parts.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export function getCommentParts(
5353
case 'relative-link':
5454
switch (typeof part.target) {
5555
case 'number': {
56-
const refl = this.page.project.files.resolve(
56+
const reflection = this.page.project.files.resolve(
5757
part.target,
5858
this.page.model.project,
5959
);
6060
let url: string | undefined;
61-
if (typeof refl === 'object' && refl.url) {
62-
url = this.getRelativeUrl(refl.url);
61+
if (typeof reflection === 'object' && reflection.url) {
62+
url = this.getRelativeUrl(reflection.url);
6363
} else {
6464
const fileName = this.page.project.files.getName(part.target);
6565
if (fileName) {

packages/typedoc-plugin-markdown/test/__scripts__/build-fixtures.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function writeMarkdown(
9797
'-options',
9898
path.join(__dirname, '..', 'fixtures', 'typedoc.cjs'),
9999
'-logLevel',
100-
'None',
100+
'Warn',
101101
'-out',
102102
fullPath,
103103
],

packages/typedoc-plugin-markdown/test/fixtures/src/comments/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* - {@link CommentEnum.MemberB}
1414
* - {@link SameName.prop}
1515
* - {@link TypeWithGenerics}
16-
* - {@link TypeDeclarationTable#declaration1 | Links to declaration1}
17-
* - {@link NotFound}
16+
* - {@link TypeDeclarationType}
17+
* - {@link TypeDeclarationType#declaration1 | Links to declaration1}
1818
*
1919
* External links:
2020
*
@@ -24,7 +24,6 @@
2424
* Relative Links:
2525
*
2626
* - [Relative Document](../../PROJECT_DOC_1.md)
27-
* - [Relative Link](../../../groups/members/opts-1/index.md)
2827
*
2928
* Relative Image Links:
3029
*
@@ -250,7 +249,7 @@ export interface InterfacePropertiesTable extends BaseInterfaceProperties {
250249
};
251250
}
252251

253-
export type TypeDeclarationTable = {
252+
export type TypeDeclarationType = {
254253
/**
255254
* The subroutine recursively parsed the hexadecimal data.
256255
* to generate the binary output for input validation.
@@ -264,7 +263,7 @@ export type TypeDeclarationTable = {
264263
declaration4: 100;
265264
};
266265

267-
export const TypeDeclarationTable = {
266+
export const TypeDeclarationConst = {
268267
declaration1: 'declaration3',
269268
declaration2: 100,
270269
};

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function functionReturningAPromise(): Promise<{
191191
});
192192
}
193193

194-
const foo = {
194+
const someConst = {
195195
/**
196196
* a comments
197197
*/
@@ -202,7 +202,7 @@ const foo = {
202202
b: '',
203203
};
204204

205-
type Foo = typeof foo;
205+
type SomeType = typeof someConst;
206206

207207
export function functionWithUnionParams(
208208
/**
@@ -227,7 +227,7 @@ export function functionWithUnionParams(
227227
*/
228228
mixedUnions:
229229
| string
230-
| Foo
230+
| SomeType
231231
| number
232232
| {
233233
/**

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

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ export type ReadonlyMappedType<T> = {
101101

102102
/**
103103
* Comments for FunctionType
104+
*
105+
* - Test link resolution for:
106+
*
107+
* - {@linkcode LiteralType} and uses {@link LiteralType#x}
108+
* - {@linkcode BasicInterface} and uses {@link BasicInterface#prop}
109+
* - {@linkcode BasicClass} and uses {@link BasicClass#prop}
110+
* - {@linkcode BasicEnum} and uses {@link BasicEnum#MemberA}
104111
*/
105112
export type FunctionType = (name: string, value: unknown) => void;
106113

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

+15-16
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ exports[`Comments should compile @links with anchors: (Output File Strategy "mod
88
- [CommentEnum.MemberB](README.md#memberb)
99
- [SameName.prop](README.md#prop-2)
1010
- [TypeWithGenerics](README.md#typewithgenericsc-d)
11+
- [TypeDeclarationType](README.md#typedeclarationtype)
1112
- [Links to declaration1](README.md#declaration1)
12-
- NotFound
1313
"
1414
`;
1515

@@ -29,8 +29,8 @@ Links using \`{@link}\` inline tags.
2929
- [CommentEnum.MemberB](enumerations/CommentEnum.md#memberb)
3030
- [SameName.prop](interfaces/SameName.md#prop)
3131
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
32-
- [Links to declaration1](type-aliases/TypeDeclarationTable.md#declaration1)
33-
- NotFound
32+
- [TypeDeclarationType](type-aliases/TypeDeclarationType.md)
33+
- [Links to declaration1](type-aliases/TypeDeclarationType.md#declaration1)
3434
3535
External links:
3636
@@ -40,7 +40,6 @@ External links:
4040
Relative Links:
4141
4242
- [Relative Document](_media/PROJECT_DOC_1.md)
43-
- [Relative Link](../../../groups/members/opts-1/index.md)
4443
4544
Relative Image Links:
4645
@@ -104,7 +103,7 @@ Some <p> html </p> inside codeblock
104103
105104
## Type Aliases
106105
107-
- [TypeDeclarationTable](type-aliases/TypeDeclarationTable.md)
106+
- [TypeDeclarationType](type-aliases/TypeDeclarationType.md)
108107
- [typeWithBlockTags](type-aliases/typeWithBlockTags.md)
109108
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
110109
@@ -114,7 +113,7 @@ Some <p> html </p> inside codeblock
114113
- [prop](variables/prop.md)
115114
- [propb](variables/propb.md)
116115
- [SameName](variables/SameName.md)
117-
- [TypeDeclarationTable](variables/TypeDeclarationTable.md)
116+
- [TypeDeclarationConst](variables/TypeDeclarationConst.md)
118117
119118
## Functions
120119
@@ -233,7 +232,7 @@ Other block tags
233232
"
234233
`;
235234
236-
exports[`Comments should get tables for emum: (Output File Strategy "members") (Option Group "1") 1`] = `
235+
exports[`Comments should get tables for enum: (Output File Strategy "members") (Option Group "1") 1`] = `
237236
"# Enumeration: EnumMembersTable
238237
239238
## Enumeration Members
@@ -244,7 +243,7 @@ exports[`Comments should get tables for emum: (Output File Strategy "members") (
244243
"
245244
`;
246245
247-
exports[`Comments should get tables for emum: (Output File Strategy "members") (Option Group "2") 1`] = `
246+
exports[`Comments should get tables for enum: (Output File Strategy "members") (Option Group "2") 1`] = `
248247
"# Enumeration: EnumMembersTable
249248
250249
## Enumeration Members
@@ -501,9 +500,9 @@ Experimental flag comments
501500
`;
502501
503502
exports[`Comments should get tables for type declarations: (Output File Strategy "members") (Option Group "1") 1`] = `
504-
"# Type Alias: TypeDeclarationTable
503+
"# Type Alias: TypeDeclarationType
505504
506-
> **TypeDeclarationTable**: \`object\`
505+
> **TypeDeclarationType**: \`object\`
507506
508507
## Type declaration
509508
@@ -520,9 +519,9 @@ exports[`Comments should get tables for type declarations: (Output File Strategy
520519
`;
521520
522521
exports[`Comments should get tables for type declarations: (Output File Strategy "members") (Option Group "1") 2`] = `
523-
"# Variable: TypeDeclarationTable
522+
"# Variable: TypeDeclarationConst
524523
525-
> **TypeDeclarationTable**: \`object\`
524+
> \`const\` **TypeDeclarationConst**: \`object\`
526525
527526
## Type declaration
528527
@@ -538,9 +537,9 @@ exports[`Comments should get tables for type declarations: (Output File Strategy
538537
`;
539538
540539
exports[`Comments should get tables for type declarations: (Output File Strategy "members") (Option Group "2") 1`] = `
541-
"# Type Alias: TypeDeclarationTable
540+
"# Type Alias: TypeDeclarationType
542541
543-
> **TypeDeclarationTable**: \\{ \`declaration1\`: \`boolean\`; \`declaration2\`: \`boolean\`; \`declaration4\`: \`100\`; \\}
542+
> **TypeDeclarationType**: \\{ \`declaration1\`: \`boolean\`; \`declaration2\`: \`boolean\`; \`declaration4\`: \`100\`; \\}
544543
545544
## Type declaration
546545
@@ -616,9 +615,9 @@ to generate the binary output for input validation.
616615
`;
617616
618617
exports[`Comments should get tables for type declarations: (Output File Strategy "members") (Option Group "2") 2`] = `
619-
"# Variable: TypeDeclarationTable
618+
"# Variable: TypeDeclarationConst
620619
621-
> **TypeDeclarationTable**: \\{ \`declaration1\`: \`string\`; \`declaration2\`: \`number\`; \\}
620+
> \`const\` **TypeDeclarationConst**: \\{ \`declaration1\`: \`string\`; \`declaration2\`: \`number\`; \\}
622621
623622
## Type declaration
624623

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

+14
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ exports[`Type Alias Reflection should compile function type: (Output File Strate
349349
350350
Comments for FunctionType
351351
352+
- Test link resolution for:
353+
354+
- [\`LiteralType\`](LiteralType.md) and uses [LiteralType#x](LiteralType.md#x)
355+
- [\`BasicInterface\`](../interfaces/BasicInterface.md) and uses [BasicInterface#prop](../interfaces/BasicInterface.md#prop)
356+
- [\`BasicClass\`](../classes/BasicClass.md) and uses [BasicClass#prop](../classes/BasicClass.md#prop)
357+
- [\`BasicEnum\`](../enumerations/BasicEnum.md) and uses [BasicEnum#MemberA](../enumerations/BasicEnum.md#membera)
358+
352359
## Parameters
353360
354361
### name
@@ -378,6 +385,13 @@ type FunctionType: (name: string, value: unknown) => void;
378385
379386
Comments for FunctionType
380387
388+
- Test link resolution for:
389+
390+
- [\`LiteralType\`](LiteralType.md) and uses [LiteralType#x](LiteralType.md)
391+
- [\`BasicInterface\`](../interfaces/BasicInterface.md) and uses [BasicInterface#prop](../interfaces/BasicInterface.md)
392+
- [\`BasicClass\`](../classes/BasicClass.md) and uses [BasicClass#prop](../classes/BasicClass.md)
393+
- [\`BasicEnum\`](../enumerations/BasicEnum.md) and uses [BasicEnum#MemberA](../enumerations/BasicEnum.md)
394+
381395
## Parameters
382396
383397
| Parameter | Type |

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,11 @@ exports[`Urls should gets Urls with media assets: outputFileStrategy: members 1`
10001000
"interfaces/CommentInterfaceExtended.md",
10011001
"interfaces/InterfacePropertiesTable.md",
10021002
"interfaces/SameName.md",
1003-
"type-aliases/TypeDeclarationTable.md",
1003+
"type-aliases/TypeDeclarationType.md",
10041004
"type-aliases/TypeWithGenerics.md",
10051005
"type-aliases/typeWithBlockTags.md",
10061006
"variables/SameName.md",
1007-
"variables/TypeDeclarationTable.md",
1007+
"variables/TypeDeclarationConst.md",
10081008
"variables/prop.md",
10091009
"variables/prop_with_underscore.md",
10101010
"variables/propb.md",
@@ -1029,11 +1029,11 @@ exports[`Urls should gets Urls with media assets: outputFileStrategy: members 2`
10291029
"Interface.InterfacePropertiesTable.md",
10301030
"Interface.SameName.md",
10311031
"README.md",
1032-
"TypeAlias.TypeDeclarationTable.md",
1032+
"TypeAlias.TypeDeclarationType.md",
10331033
"TypeAlias.TypeWithGenerics.md",
10341034
"TypeAlias.typeWithBlockTags.md",
10351035
"Variable.SameName.md",
1036-
"Variable.TypeDeclarationTable.md",
1036+
"Variable.TypeDeclarationConst.md",
10371037
"Variable._prop_with_underscore.md",
10381038
"Variable.prop.md",
10391039
"Variable.propb.md",

0 commit comments

Comments
 (0)