@@ -177,6 +177,10 @@ function isHostTrusted(host: string): boolean {
177
177
return TrustedSVGSources . indexOf ( host . toLowerCase ( ) ) > - 1 ;
178
178
}
179
179
180
+ function isGitHubRepository ( repository : string ) : boolean {
181
+ return / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ | ^ g i t @ g i t h u b \. c o m : / . test ( repository || '' ) ;
182
+ }
183
+
180
184
class ManifestProcessor extends BaseProcessor {
181
185
182
186
constructor ( manifest : Manifest ) {
@@ -189,7 +193,7 @@ class ManifestProcessor extends BaseProcessor {
189
193
}
190
194
191
195
const repository = getRepositoryUrl ( manifest . repository ) ;
192
- const isGitHub = / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ | ^ g i t @ g i t h u b \. c o m : / . test ( repository || '' ) ;
196
+ const isGitHub = isGitHubRepository ( repository ) ;
193
197
194
198
let enableMarketplaceQnA : boolean | undefined ;
195
199
let customerQnALink : string | undefined ;
@@ -348,6 +352,8 @@ export class MarkdownProcessor extends BaseProcessor {
348
352
349
353
private baseContentUrl : string ;
350
354
private baseImagesUrl : string ;
355
+ private isGitHub : boolean ;
356
+ private repositoryUrl : string ;
351
357
352
358
constructor ( manifest : Manifest , private name : string , private regexp : RegExp , private assetType : string , options : IPackageOptions = { } ) {
353
359
super ( manifest ) ;
@@ -356,6 +362,8 @@ export class MarkdownProcessor extends BaseProcessor {
356
362
357
363
this . baseContentUrl = options . baseContentUrl || ( guess && guess . content ) ;
358
364
this . baseImagesUrl = options . baseImagesUrl || options . baseContentUrl || ( guess && guess . images ) ;
365
+ this . repositoryUrl = ( guess && guess . repository ) ;
366
+ this . isGitHub = isGitHubRepository ( this . repositoryUrl ) ;
359
367
}
360
368
361
369
async onFile ( file : IFile ) : Promise < IFile > {
@@ -394,9 +402,36 @@ export class MarkdownProcessor extends BaseProcessor {
394
402
395
403
return `${ isImage } [${ title } ](${ urljoin ( prefix , link ) } )` ;
396
404
} ;
397
-
405
+ // Replace Markdown links with urls
398
406
contents = contents . replace ( markdownPathRegex , urlReplace ) ;
399
407
408
+ const markdownIssueRegex = / ( \s | \n ) ( [ \w \d _ - ] + \/ [ \w \d _ - ] + ) ? # ( \d + ) \b / g
409
+ const issueReplace = ( all : string , prefix : string , ownerAndRepositoryName : string , issueNumber : string ) : string => {
410
+ let result = all ;
411
+ let owner : string ;
412
+ let repositoryName : string ;
413
+
414
+ if ( ownerAndRepositoryName ) {
415
+ [ owner , repositoryName ] = ownerAndRepositoryName . split ( '/' , 2 ) ;
416
+ }
417
+
418
+ if ( this . isGitHub ) {
419
+ if ( owner && repositoryName && issueNumber ) {
420
+ // Issue in external repository
421
+ const issueUrl = urljoin ( 'https://github.com' , owner , repositoryName , 'issues' , issueNumber ) ;
422
+ result = prefix + `[${ owner } /${ repositoryName } #${ issueNumber } ](${ issueUrl } )` ;
423
+
424
+ } else if ( ! owner && ! repositoryName && issueNumber ) {
425
+ // Issue in own repository
426
+ result = prefix + `[#${ issueNumber } ](${ urljoin ( this . repositoryUrl , 'issues' , issueNumber ) } )` ;
427
+ }
428
+ }
429
+
430
+ return result ;
431
+ }
432
+ // Replace Markdown issue references with urls
433
+ contents = contents . replace ( markdownIssueRegex , issueReplace ) ;
434
+
400
435
const html = markdownit ( { html : true } ) . render ( contents ) ;
401
436
const $ = cheerio . load ( html ) ;
402
437
@@ -428,7 +463,7 @@ export class MarkdownProcessor extends BaseProcessor {
428
463
}
429
464
430
465
// GitHub heuristics
431
- private guessBaseUrls ( ) : { content : string ; images : string ; } {
466
+ private guessBaseUrls ( ) : { content : string ; images : string ; repository : string } {
432
467
let repository = null ;
433
468
434
469
if ( typeof this . manifest . repository === 'string' ) {
@@ -453,7 +488,8 @@ export class MarkdownProcessor extends BaseProcessor {
453
488
454
489
return {
455
490
content : `https://github.com/${ account } /${ repositoryName } /blob/master` ,
456
- images : `https://github.com/${ account } /${ repositoryName } /raw/master`
491
+ images : `https://github.com/${ account } /${ repositoryName } /raw/master` ,
492
+ repository : `https://github.com/${ account } /${ repositoryName } `
457
493
} ;
458
494
}
459
495
}
0 commit comments