@@ -1274,29 +1274,69 @@ class Repository {
1274
1274
if ( ! this . markedOptions ) {
1275
1275
let issueParser = "<a href=\"/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/issues/view/?" + this . address + "/$1@$2\">#$1@$2</a>" ;
1276
1276
let pullRequestParser = "<a href=\"/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/pull-requests/view/?" + this . address + "/$1@$2\">#P$1@$2</a>" ;
1277
+ let allowed_prefixes = [ "/gitcenter.bit" , "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t" ] ;
1278
+
1279
+ let self = this ;
1277
1280
1278
1281
let renderer = new marked . Renderer ( ) ;
1279
1282
renderer . image = function ( href , title , text ) {
1280
1283
if ( href . indexOf ( "./" ) == 0 ) {
1281
1284
// Relative to current file showing
1282
1285
href = href . replace ( "./" , "" ) ;
1283
1286
href = root ? root + "/" + href : href ;
1284
- if ( window . branch ) {
1285
- href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" + branch ;
1286
- } else {
1287
- href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" ;
1288
- }
1289
- } else if ( href [ 0 ] == "/" ) {
1287
+ } else if ( href [ 0 ] == "/" && ! allowed_prefixes . some ( prefix => link . indexOf ( prefix ) == 0 ) ) {
1290
1288
// Relative to repository root
1291
1289
href = href . replace ( "/" , "" ) ;
1292
- if ( window . branch ) {
1293
- href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" + branch ;
1294
- } else {
1295
- href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" ;
1296
- }
1290
+ } else {
1291
+ return this . __proto__ . image . call ( this , href , title , text ) ; // super() analog
1292
+ }
1293
+
1294
+ let nodeId = "image_placeholder_" + Math . random ( ) . toString ( 36 ) . substr ( 2 ) ;
1295
+
1296
+ let node = document . createElement ( "div" ) ;
1297
+ node . className = "image-placeholder" ;
1298
+ node . id = nodeId ;
1299
+ node . textContent = "Loading " + ( title || href ) + "..." ;
1300
+
1301
+ let filename = href . split ( "/" ) . slice ( - 1 ) [ 0 ] || "" ;
1302
+ let extension = filename . split ( "." ) . slice ( - 1 ) [ 0 ] || "" ;
1303
+ let type = {
1304
+ tif : "image/tiff" ,
1305
+ tiff : "image/tiff" ,
1306
+ gif : "image/gif" ,
1307
+ jpeg : "image/jpeg" ,
1308
+ jpg : "image/jpeg" ,
1309
+ jif : "image/jpeg" ,
1310
+ jiff : "image/jpeg" ,
1311
+ jp2 : "image/jpeg" ,
1312
+ jpx : "image/jpeg" ,
1313
+ j2k : "image/jpeg" ,
1314
+ j2c : "image/jpeg" ,
1315
+ png : "image/png" ,
1316
+ svg : "image/svg+xml" ,
1317
+ webp : "image/webp"
1318
+ } [ extension ] ;
1319
+ if ( ! type ) {
1320
+ node . textContent = "Could not detect image type of " + ( title || href ) ;
1321
+ return node . outerHTML ;
1297
1322
}
1298
1323
1299
- return this . __proto__ . image . call ( this , href , title , text ) ; // super() analog
1324
+ // Load image manually
1325
+ self . getFile ( branch , href )
1326
+ . then ( blob => {
1327
+ blob = new Blob ( [ blob ] , { type : type } ) ;
1328
+ let url = URL . createObjectURL ( blob ) ;
1329
+
1330
+ let node = document . getElementById ( nodeId ) ;
1331
+ if ( node ) {
1332
+ let img = document . createElement ( "img" ) ;
1333
+ img . src = url ;
1334
+ img . title = title ;
1335
+ node . parentNode . replaceChild ( img , node ) ;
1336
+ }
1337
+ } ) ;
1338
+
1339
+ return node . outerHTML ;
1300
1340
} ;
1301
1341
renderer . text = function ( text ) {
1302
1342
return text
@@ -1313,7 +1353,7 @@ class Repository {
1313
1353
} else {
1314
1354
link = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" ;
1315
1355
}
1316
- } else if ( link [ 0 ] == "/" ) {
1356
+ } else if ( link [ 0 ] == "/" && ! allowed_prefixes . some ( prefix => link . indexOf ( prefix ) == 0 ) ) {
1317
1357
// Relative to repository root
1318
1358
link = link . replace ( "/" , "" ) ;
1319
1359
if ( window . branch ) {
0 commit comments