@@ -32,21 +32,28 @@ export type ExternalSymbolResolver = (
3232 symbolId : ReflectionSymbolId | undefined ,
3333) => ExternalResolveResult | string | undefined ;
3434
35+ export type LinkResolverOptions = {
36+ preserveLinkText : boolean ;
37+ } ;
38+
3539export function resolveLinks (
3640 comment : Comment ,
3741 reflection : Reflection ,
3842 externalResolver : ExternalSymbolResolver ,
43+ options : LinkResolverOptions ,
3944) {
4045 comment . summary = resolvePartLinks (
4146 reflection ,
4247 comment . summary ,
4348 externalResolver ,
49+ options ,
4450 ) ;
4551 for ( const tag of comment . blockTags ) {
4652 tag . content = resolvePartLinks (
4753 reflection ,
4854 tag . content ,
4955 externalResolver ,
56+ options ,
5057 ) ;
5158 }
5259
@@ -55,6 +62,7 @@ export function resolveLinks(
5562 reflection ,
5663 reflection . readme ,
5764 externalResolver ,
65+ options ,
5866 ) ;
5967 }
6068}
@@ -63,24 +71,26 @@ export function resolvePartLinks(
6371 reflection : Reflection ,
6472 parts : readonly CommentDisplayPart [ ] ,
6573 externalResolver : ExternalSymbolResolver ,
74+ options : LinkResolverOptions ,
6675) : CommentDisplayPart [ ] {
6776 return parts . flatMap ( ( part ) =>
68- processPart ( reflection , part , externalResolver ) ,
77+ processPart ( reflection , part , externalResolver , options ) ,
6978 ) ;
7079}
7180
7281function processPart (
7382 reflection : Reflection ,
7483 part : CommentDisplayPart ,
7584 externalResolver : ExternalSymbolResolver ,
85+ options : LinkResolverOptions ,
7686) : CommentDisplayPart | CommentDisplayPart [ ] {
7787 if ( part . kind === "inline-tag" ) {
7888 if (
7989 part . tag === "@link" ||
8090 part . tag === "@linkcode" ||
8191 part . tag === "@linkplain"
8292 ) {
83- return resolveLinkTag ( reflection , part , externalResolver ) ;
93+ return resolveLinkTag ( reflection , part , externalResolver , options ) ;
8494 }
8595 }
8696
@@ -91,6 +101,7 @@ function resolveLinkTag(
91101 reflection : Reflection ,
92102 part : InlineTagDisplayPart ,
93103 externalResolver : ExternalSymbolResolver ,
104+ options : LinkResolverOptions ,
94105) : InlineTagDisplayPart {
95106 let defaultDisplayText = "" ;
96107 let pos = 0 ;
@@ -112,7 +123,9 @@ function resolveLinkTag(
112123 if ( tsTarget ) {
113124 target = tsTarget ;
114125 pos = end ;
115- defaultDisplayText = part . tsLinkText || target . name ;
126+ defaultDisplayText =
127+ part . tsLinkText ||
128+ ( options . preserveLinkText ? part . text : target . name ) ;
116129 } else if ( declRef ) {
117130 // If we didn't find a target, we might be pointing to a symbol in another project that will be merged in
118131 // or some external symbol, so ask external resolvers to try resolution. Don't use regular declaration ref
@@ -127,7 +140,9 @@ function resolveLinkTag(
127140 : undefined ,
128141 ) ;
129142
130- defaultDisplayText = part . text . substring ( 0 , pos ) ;
143+ defaultDisplayText = options . preserveLinkText
144+ ? part . text
145+ : part . text . substring ( 0 , pos ) ;
131146
132147 switch ( typeof externalResolveResult ) {
133148 case "string" :
@@ -147,7 +162,9 @@ function resolveLinkTag(
147162 pos = declRef [ 1 ] ;
148163
149164 if ( target ) {
150- defaultDisplayText = target . name ;
165+ defaultDisplayText = options . preserveLinkText
166+ ? part . text
167+ : target . name ;
151168 } else {
152169 // If we didn't find a link, it might be a @link tag to an external symbol, check that next.
153170 const externalResolveResult = externalResolver (
@@ -159,7 +176,9 @@ function resolveLinkTag(
159176 : undefined ,
160177 ) ;
161178
162- defaultDisplayText = part . text . substring ( 0 , pos ) ;
179+ defaultDisplayText = options . preserveLinkText
180+ ? part . text
181+ : part . text . substring ( 0 , pos ) ;
163182
164183 switch ( typeof externalResolveResult ) {
165184 case "string" :
0 commit comments