@@ -239,6 +239,26 @@ function formatExample(blocks?: any[]) {
239239 }
240240}
241241
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+
242262/**
243263 * Format a documentation item to a string
244264 *
@@ -251,7 +271,6 @@ function formatExample(blocks?: any[]) {
251271function formatItem ( _item : any , _package : string , version : string , member ?: string ) {
252272 const itemLink = docsLink ( _item , _package , version , member ) ;
253273 const item = effectiveItem ( _item , member ) ;
254- const sourceUrl = item . sourceURL ? `${ item . sourceURL } ${ item . sourceLine ? `#L${ item . sourceLine } ` : '' } ` : null ;
255274
256275 const [ emojiId , emojiName ] = itemKindEmoji ( item . kind , version === 'main' ) ;
257276
@@ -268,8 +287,7 @@ function formatItem(_item: any, _package: string, version: string, member?: stri
268287 parts . push ( underline ( bold ( hyperlink ( item . displayName , itemLink ) ) ) ) ;
269288
270289 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 ) ;
273291 const middlePart = item . isDeprecated ? strikethrough ( parts . join ( ' ' ) ) : parts . join ( ' ' ) ;
274292
275293 const lines : string [ ] = [ [ head , middlePart , tail ] . join ( ' ' ) ] ;
0 commit comments