11import ts from "typescript" ;
22import {
3- type Comment ,
43 type CommentDisplayPart ,
5- DeclarationReflection ,
64 type InlineTagDisplayPart ,
5+ makeRecursiveVisitor ,
76 Reflection ,
87 ReflectionKind ,
98 ReflectionSymbolId ,
@@ -35,27 +34,28 @@ export type LinkResolverOptions = {
3534} ;
3635
3736export function resolveLinks (
38- comment : Comment ,
3937 reflection : Reflection ,
4038 externalResolver : ExternalSymbolResolver ,
4139 options : LinkResolverOptions ,
4240) {
43- comment . summary = resolvePartLinks (
44- reflection ,
45- comment . summary ,
46- externalResolver ,
47- options ,
48- ) ;
49- for ( const tag of comment . blockTags ) {
50- tag . content = resolvePartLinks (
41+ if ( reflection . comment ) {
42+ reflection . comment . summary = resolvePartLinks (
5143 reflection ,
52- tag . content ,
44+ reflection . comment . summary ,
5345 externalResolver ,
5446 options ,
5547 ) ;
48+ for ( const tag of reflection . comment . blockTags ) {
49+ tag . content = resolvePartLinks (
50+ reflection ,
51+ tag . content ,
52+ externalResolver ,
53+ options ,
54+ ) ;
55+ }
5656 }
5757
58- if ( reflection instanceof DeclarationReflection && reflection . readme ) {
58+ if ( ( reflection . isDeclaration ( ) || reflection . isProject ( ) ) && reflection . readme ) {
5959 reflection . readme = resolvePartLinks (
6060 reflection ,
6161 reflection . readme ,
@@ -64,6 +64,18 @@ export function resolveLinks(
6464 ) ;
6565 }
6666
67+ if ( reflection . isDeclaration ( ) ) {
68+ reflection . type ?. visit (
69+ makeRecursiveVisitor ( {
70+ union : ( type ) => {
71+ type . elementSummaries = type . elementSummaries ?. map (
72+ ( parts ) => resolvePartLinks ( reflection , parts , externalResolver , options ) ,
73+ ) ;
74+ } ,
75+ } ) ,
76+ ) ;
77+ }
78+
6779 if ( reflection . isDocument ( ) ) {
6880 reflection . content = resolvePartLinks (
6981 reflection ,
@@ -72,6 +84,57 @@ export function resolveLinks(
7284 options ,
7385 ) ;
7486 }
87+
88+ if (
89+ reflection . isParameter ( ) &&
90+ reflection . type ?. type === "reference" &&
91+ reflection . type . highlightedProperties
92+ ) {
93+ const resolved = new Map (
94+ Array . from (
95+ reflection . type . highlightedProperties ,
96+ ( [ name , parts ] ) => {
97+ return [
98+ name ,
99+ resolvePartLinks ( reflection , parts , externalResolver , options ) ,
100+ ] ;
101+ } ,
102+ ) ,
103+ ) ;
104+
105+ reflection . type . highlightedProperties = resolved ;
106+ }
107+
108+ if ( reflection . isContainer ( ) ) {
109+ if ( reflection . groups ) {
110+ for ( const group of reflection . groups ) {
111+ if ( group . description ) {
112+ group . description = resolvePartLinks (
113+ reflection ,
114+ group . description ,
115+ externalResolver ,
116+ options ,
117+ ) ;
118+ }
119+
120+ if ( group . categories ) {
121+ for ( const cat of group . categories ) {
122+ if ( cat . description ) {
123+ cat . description = resolvePartLinks ( reflection , cat . description , externalResolver , options ) ;
124+ }
125+ }
126+ }
127+ }
128+ }
129+
130+ if ( reflection . categories ) {
131+ for ( const cat of reflection . categories ) {
132+ if ( cat . description ) {
133+ cat . description = resolvePartLinks ( reflection , cat . description , externalResolver , options ) ;
134+ }
135+ }
136+ }
137+ }
75138}
76139
77140export function resolvePartLinks (
@@ -133,10 +196,10 @@ function resolveLinkTag(
133196
134197 if ( tsTargets . length ) {
135198 // Find the target most likely to have a real url in the generated documentation
136- // 1 . A direct export (class, interface, variable)
137- // 2 . A property of a direct export (class/interface property)
138- // 3 . A property of a type of an export (property on type alias)
139- // 4 . Whatever the first symbol found was
199+ // 4 . A direct export (class, interface, variable)
200+ // 3 . A property of a direct export (class/interface property)
201+ // 2 . A property of a type of an export (property on type alias)
202+ // 1 . Whatever the first symbol found was
140203 target = maxElementByScore ( tsTargets , ( r ) => {
141204 if ( r . kindOf ( ReflectionKind . SomeExport ) ) {
142205 return 4 ;
0 commit comments