@@ -239,6 +239,26 @@ function formatExample(blocks?: any[]) {
239
239
}
240
240
}
241
241
242
+ /**
243
+ * Format the provided docs source item to a source link, if available
244
+ *
245
+ * @param item - The docs source item to format
246
+ * @param _package - The package to use
247
+ * @param version - The version to use
248
+ * @returns The formatted link, if available, otherwise the provided versionstring
249
+ */
250
+ function formatSourceURL ( item : any , _package : string , version : string ) {
251
+ const sourceUrl = item . sourceURL ;
252
+ const versionString = inlineCode ( `${ _package } @${ version } ` ) ;
253
+
254
+ if ( ! item . sourceURL ?. startsWith ( 'http' ) ) {
255
+ return versionString ;
256
+ }
257
+
258
+ const link = `${ sourceUrl } ${ item . sourceLine ? `#L${ item . sourceLine } ` : '' } ` ;
259
+ return hyperlink ( versionString , link , 'source code' ) ;
260
+ }
261
+
242
262
/**
243
263
* Format a documentation item to a string
244
264
*
@@ -251,7 +271,6 @@ function formatExample(blocks?: any[]) {
251
271
function formatItem ( _item : any , _package : string , version : string , member ?: string ) {
252
272
const itemLink = docsLink ( _item , _package , version , member ) ;
253
273
const item = effectiveItem ( _item , member ) ;
254
- const sourceUrl = item . sourceURL ? `${ item . sourceURL } ${ item . sourceLine ? `#L${ item . sourceLine } ` : '' } ` : null ;
255
274
256
275
const [ emojiId , emojiName ] = itemKindEmoji ( item . kind , version === 'main' ) ;
257
276
@@ -268,8 +287,7 @@ function formatItem(_item: any, _package: string, version: string, member?: stri
268
287
parts . push ( underline ( bold ( hyperlink ( item . displayName , itemLink ) ) ) ) ;
269
288
270
289
const head = `<:${ emojiName } :${ emojiId } >` ;
271
- const versionString = inlineCode ( `${ _package } @${ version } ` ) ;
272
- const tail = sourceUrl ? ` ${ hyperlink ( versionString , sourceUrl , 'source code' ) } ` : versionString ;
290
+ const tail = formatSourceURL ( item , _package , version ) ;
273
291
const middlePart = item . isDeprecated ? strikethrough ( parts . join ( ' ' ) ) : parts . join ( ' ' ) ;
274
292
275
293
const lines : string [ ] = [ [ head , middlePart , tail ] . join ( ' ' ) ] ;
0 commit comments