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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 32 additions & 19 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 7 additions & 0 deletions
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

0 commit comments

Comments
 (0)