@@ -32,21 +32,28 @@ export type ExternalSymbolResolver = (
32
32
symbolId : ReflectionSymbolId | undefined ,
33
33
) => ExternalResolveResult | string | undefined ;
34
34
35
+ export type LinkResolverOptions = {
36
+ preserveLinkText : boolean ;
37
+ } ;
38
+
35
39
export function resolveLinks (
36
40
comment : Comment ,
37
41
reflection : Reflection ,
38
42
externalResolver : ExternalSymbolResolver ,
43
+ options : LinkResolverOptions ,
39
44
) {
40
45
comment . summary = resolvePartLinks (
41
46
reflection ,
42
47
comment . summary ,
43
48
externalResolver ,
49
+ options ,
44
50
) ;
45
51
for ( const tag of comment . blockTags ) {
46
52
tag . content = resolvePartLinks (
47
53
reflection ,
48
54
tag . content ,
49
55
externalResolver ,
56
+ options ,
50
57
) ;
51
58
}
52
59
@@ -55,6 +62,7 @@ export function resolveLinks(
55
62
reflection ,
56
63
reflection . readme ,
57
64
externalResolver ,
65
+ options ,
58
66
) ;
59
67
}
60
68
}
@@ -63,24 +71,26 @@ export function resolvePartLinks(
63
71
reflection : Reflection ,
64
72
parts : readonly CommentDisplayPart [ ] ,
65
73
externalResolver : ExternalSymbolResolver ,
74
+ options : LinkResolverOptions ,
66
75
) : CommentDisplayPart [ ] {
67
76
return parts . flatMap ( ( part ) =>
68
- processPart ( reflection , part , externalResolver ) ,
77
+ processPart ( reflection , part , externalResolver , options ) ,
69
78
) ;
70
79
}
71
80
72
81
function processPart (
73
82
reflection : Reflection ,
74
83
part : CommentDisplayPart ,
75
84
externalResolver : ExternalSymbolResolver ,
85
+ options : LinkResolverOptions ,
76
86
) : CommentDisplayPart | CommentDisplayPart [ ] {
77
87
if ( part . kind === "inline-tag" ) {
78
88
if (
79
89
part . tag === "@link" ||
80
90
part . tag === "@linkcode" ||
81
91
part . tag === "@linkplain"
82
92
) {
83
- return resolveLinkTag ( reflection , part , externalResolver ) ;
93
+ return resolveLinkTag ( reflection , part , externalResolver , options ) ;
84
94
}
85
95
}
86
96
@@ -91,6 +101,7 @@ function resolveLinkTag(
91
101
reflection : Reflection ,
92
102
part : InlineTagDisplayPart ,
93
103
externalResolver : ExternalSymbolResolver ,
104
+ options : LinkResolverOptions ,
94
105
) : InlineTagDisplayPart {
95
106
let defaultDisplayText = "" ;
96
107
let pos = 0 ;
@@ -112,7 +123,9 @@ function resolveLinkTag(
112
123
if ( tsTarget ) {
113
124
target = tsTarget ;
114
125
pos = end ;
115
- defaultDisplayText = part . tsLinkText || target . name ;
126
+ defaultDisplayText =
127
+ part . tsLinkText ||
128
+ ( options . preserveLinkText ? part . text : target . name ) ;
116
129
} else if ( declRef ) {
117
130
// If we didn't find a target, we might be pointing to a symbol in another project that will be merged in
118
131
// or some external symbol, so ask external resolvers to try resolution. Don't use regular declaration ref
@@ -127,7 +140,9 @@ function resolveLinkTag(
127
140
: undefined ,
128
141
) ;
129
142
130
- defaultDisplayText = part . text . substring ( 0 , pos ) ;
143
+ defaultDisplayText = options . preserveLinkText
144
+ ? part . text
145
+ : part . text . substring ( 0 , pos ) ;
131
146
132
147
switch ( typeof externalResolveResult ) {
133
148
case "string" :
@@ -147,7 +162,9 @@ function resolveLinkTag(
147
162
pos = declRef [ 1 ] ;
148
163
149
164
if ( target ) {
150
- defaultDisplayText = target . name ;
165
+ defaultDisplayText = options . preserveLinkText
166
+ ? part . text
167
+ : target . name ;
151
168
} else {
152
169
// If we didn't find a link, it might be a @link tag to an external symbol, check that next.
153
170
const externalResolveResult = externalResolver (
@@ -159,7 +176,9 @@ function resolveLinkTag(
159
176
: undefined ,
160
177
) ;
161
178
162
- defaultDisplayText = part . text . substring ( 0 , pos ) ;
179
+ defaultDisplayText = options . preserveLinkText
180
+ ? part . text
181
+ : part . text . substring ( 0 , pos ) ;
163
182
164
183
switch ( typeof externalResolveResult ) {
165
184
case "string" :
0 commit comments