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