@@ -3170,15 +3170,15 @@ process.umask = function() { return 0; };
3170
3170
var diff = printerUtils . diffHighlight ( oldLine . content , newLine . content , that . config ) ;
3171
3171
3172
3172
processedOldLines +=
3173
- that . makeLineHtml ( deleteType , oldLine . oldNumber , oldLine . newNumber ,
3173
+ that . makeLineHtml ( file . isCombined , deleteType , oldLine . oldNumber , oldLine . newNumber ,
3174
3174
diff . first . line , diff . first . prefix ) ;
3175
3175
processedNewLines +=
3176
- that . makeLineHtml ( insertType , newLine . oldNumber , newLine . newNumber ,
3176
+ that . makeLineHtml ( file . isCombined , insertType , newLine . oldNumber , newLine . newNumber ,
3177
3177
diff . second . line , diff . second . prefix ) ;
3178
3178
}
3179
3179
3180
3180
lines += processedOldLines + processedNewLines ;
3181
- lines += that . _processLines ( oldLines . slice ( common ) , newLines . slice ( common ) ) ;
3181
+ lines += that . _processLines ( file . isCombined , oldLines . slice ( common ) , newLines . slice ( common ) ) ;
3182
3182
} ) ;
3183
3183
3184
3184
oldLines = [ ] ;
@@ -3195,9 +3195,9 @@ process.umask = function() { return 0; };
3195
3195
}
3196
3196
3197
3197
if ( line . type === diffParser . LINE_TYPE . CONTEXT ) {
3198
- lines += that . makeLineHtml ( line . type , line . oldNumber , line . newNumber , escapedLine ) ;
3198
+ lines += that . makeLineHtml ( file . isCombined , line . type , line . oldNumber , line . newNumber , escapedLine ) ;
3199
3199
} else if ( line . type === diffParser . LINE_TYPE . INSERTS && ! oldLines . length ) {
3200
- lines += that . makeLineHtml ( line . type , line . oldNumber , line . newNumber , escapedLine ) ;
3200
+ lines += that . makeLineHtml ( file . isCombined , line . type , line . oldNumber , line . newNumber , escapedLine ) ;
3201
3201
} else if ( line . type === diffParser . LINE_TYPE . DELETES ) {
3202
3202
oldLines . push ( line ) ;
3203
3203
} else if ( line . type === diffParser . LINE_TYPE . INSERTS && Boolean ( oldLines . length ) ) {
@@ -3214,37 +3214,46 @@ process.umask = function() { return 0; };
3214
3214
} ) . join ( '\n' ) ;
3215
3215
} ;
3216
3216
3217
- LineByLinePrinter . prototype . _processLines = function ( oldLines , newLines ) {
3217
+ LineByLinePrinter . prototype . _processLines = function ( isCombined , oldLines , newLines ) {
3218
3218
var lines = '' ;
3219
3219
3220
3220
for ( var i = 0 ; i < oldLines . length ; i ++ ) {
3221
3221
var oldLine = oldLines [ i ] ;
3222
3222
var oldEscapedLine = utils . escape ( oldLine . content ) ;
3223
- lines += this . makeLineHtml ( oldLine . type , oldLine . oldNumber , oldLine . newNumber , oldEscapedLine ) ;
3223
+ lines += this . makeLineHtml ( isCombined , oldLine . type , oldLine . oldNumber , oldLine . newNumber , oldEscapedLine ) ;
3224
3224
}
3225
3225
3226
3226
for ( var j = 0 ; j < newLines . length ; j ++ ) {
3227
3227
var newLine = newLines [ j ] ;
3228
3228
var newEscapedLine = utils . escape ( newLine . content ) ;
3229
- lines += this . makeLineHtml ( newLine . type , newLine . oldNumber , newLine . newNumber , newEscapedLine ) ;
3229
+ lines += this . makeLineHtml ( isCombined , newLine . type , newLine . oldNumber , newLine . newNumber , newEscapedLine ) ;
3230
3230
}
3231
3231
3232
3232
return lines ;
3233
3233
} ;
3234
3234
3235
- LineByLinePrinter . prototype . makeLineHtml = function ( type , oldNumber , newNumber , content , prefix ) {
3235
+ LineByLinePrinter . prototype . makeLineHtml = function ( isCombined , type , oldNumber , newNumber , content , possiblePrefix ) {
3236
3236
var lineNumberTemplate = hoganUtils . render ( baseTemplatesPath , 'numbers' , {
3237
3237
oldNumber : utils . valueOrEmpty ( oldNumber ) ,
3238
3238
newNumber : utils . valueOrEmpty ( newNumber )
3239
3239
} ) ;
3240
3240
3241
+ var lineWithoutPrefix = content ;
3242
+ var prefix = possiblePrefix ;
3243
+
3244
+ if ( ! prefix ) {
3245
+ var lineWithPrefix = printerUtils . separatePrefix ( isCombined , content ) ;
3246
+ prefix = lineWithPrefix . prefix ;
3247
+ lineWithoutPrefix = lineWithPrefix . line ;
3248
+ }
3249
+
3241
3250
return hoganUtils . render ( genericTemplatesPath , 'line' ,
3242
3251
{
3243
3252
type : type ,
3244
3253
lineClass : 'd2h-code-linenumber' ,
3245
3254
contentClass : 'd2h-code-line' ,
3246
- prefix : prefix && utils . convertWhiteSpaceToNonBreakingSpace ( prefix ) ,
3247
- content : content && utils . convertWhiteSpaceToNonBreakingSpace ( content ) ,
3255
+ prefix : prefix ,
3256
+ content : lineWithoutPrefix ,
3248
3257
lineNumber : lineNumberTemplate
3249
3258
} ) ;
3250
3259
} ;
@@ -3277,6 +3286,24 @@ process.umask = function() { return 0; };
3277
3286
function PrinterUtils ( ) {
3278
3287
}
3279
3288
3289
+ PrinterUtils . prototype . separatePrefix = function ( isCombined , line ) {
3290
+ var prefix ;
3291
+ var lineWithoutPrefix ;
3292
+
3293
+ if ( isCombined ) {
3294
+ prefix = line . substring ( 0 , 2 ) ;
3295
+ lineWithoutPrefix = line . substring ( 2 ) ;
3296
+ } else {
3297
+ prefix = line . substring ( 0 , 1 ) ;
3298
+ lineWithoutPrefix = line . substring ( 1 ) ;
3299
+ }
3300
+
3301
+ return {
3302
+ 'prefix' : prefix ,
3303
+ 'line' : lineWithoutPrefix
3304
+ } ;
3305
+ } ;
3306
+
3280
3307
PrinterUtils . prototype . getHtmlId = function ( file ) {
3281
3308
var hashCode = function ( text ) {
3282
3309
var i , chr , len ;
@@ -3747,18 +3774,18 @@ process.umask = function() { return 0; };
3747
3774
var diff = printerUtils . diffHighlight ( oldLine . content , newLine . content , that . config ) ;
3748
3775
3749
3776
fileHtml . left +=
3750
- that . generateSingleLineHtml ( deleteType , oldLine . oldNumber ,
3777
+ that . generateSingleLineHtml ( file . isCombined , deleteType , oldLine . oldNumber ,
3751
3778
diff . first . line , diff . first . prefix ) ;
3752
3779
fileHtml . right +=
3753
- that . generateSingleLineHtml ( insertType , newLine . newNumber ,
3780
+ that . generateSingleLineHtml ( file . isCombined , insertType , newLine . newNumber ,
3754
3781
diff . second . line , diff . second . prefix ) ;
3755
3782
}
3756
3783
3757
3784
if ( max > common ) {
3758
3785
var oldSlice = oldLines . slice ( common ) ;
3759
3786
var newSlice = newLines . slice ( common ) ;
3760
3787
3761
- var tmpHtml = that . processLines ( oldSlice , newSlice ) ;
3788
+ var tmpHtml = that . processLines ( file . isCombined , oldSlice , newSlice ) ;
3762
3789
fileHtml . left += tmpHtml . left ;
3763
3790
fileHtml . right += tmpHtml . right ;
3764
3791
}
@@ -3779,11 +3806,11 @@ process.umask = function() { return 0; };
3779
3806
}
3780
3807
3781
3808
if ( line . type === diffParser . LINE_TYPE . CONTEXT ) {
3782
- fileHtml . left += that . generateSingleLineHtml ( line . type , line . oldNumber , escapedLine , prefix ) ;
3783
- fileHtml . right += that . generateSingleLineHtml ( line . type , line . newNumber , escapedLine , prefix ) ;
3809
+ fileHtml . left += that . generateSingleLineHtml ( file . isCombined , line . type , line . oldNumber , escapedLine , prefix ) ;
3810
+ fileHtml . right += that . generateSingleLineHtml ( file . isCombined , line . type , line . newNumber , escapedLine , prefix ) ;
3784
3811
} else if ( line . type === diffParser . LINE_TYPE . INSERTS && ! oldLines . length ) {
3785
- fileHtml . left += that . generateSingleLineHtml ( diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3786
- fileHtml . right += that . generateSingleLineHtml ( line . type , line . newNumber , escapedLine , prefix ) ;
3812
+ fileHtml . left += that . generateSingleLineHtml ( file . isCombined , diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3813
+ fileHtml . right += that . generateSingleLineHtml ( file . isCombined , line . type , line . newNumber , escapedLine , prefix ) ;
3787
3814
} else if ( line . type === diffParser . LINE_TYPE . DELETES ) {
3788
3815
oldLines . push ( line ) ;
3789
3816
} else if ( line . type === diffParser . LINE_TYPE . INSERTS && Boolean ( oldLines . length ) ) {
@@ -3800,7 +3827,7 @@ process.umask = function() { return 0; };
3800
3827
return fileHtml ;
3801
3828
} ;
3802
3829
3803
- SideBySidePrinter . prototype . processLines = function ( oldLines , newLines ) {
3830
+ SideBySidePrinter . prototype . processLines = function ( isCombined , oldLines , newLines ) {
3804
3831
var that = this ;
3805
3832
var fileHtml = { } ;
3806
3833
fileHtml . left = '' ;
@@ -3826,14 +3853,14 @@ process.umask = function() { return 0; };
3826
3853
}
3827
3854
3828
3855
if ( oldLine && newLine ) {
3829
- fileHtml . left += that . generateSingleLineHtml ( oldLine . type , oldLine . oldNumber , oldContent , oldPrefix ) ;
3830
- fileHtml . right += that . generateSingleLineHtml ( newLine . type , newLine . newNumber , newContent , newPrefix ) ;
3856
+ fileHtml . left += that . generateSingleLineHtml ( isCombined , oldLine . type , oldLine . oldNumber , oldContent , oldPrefix ) ;
3857
+ fileHtml . right += that . generateSingleLineHtml ( isCombined , newLine . type , newLine . newNumber , newContent , newPrefix ) ;
3831
3858
} else if ( oldLine ) {
3832
- fileHtml . left += that . generateSingleLineHtml ( oldLine . type , oldLine . oldNumber , oldContent , oldPrefix ) ;
3833
- fileHtml . right += that . generateSingleLineHtml ( diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3859
+ fileHtml . left += that . generateSingleLineHtml ( isCombined , oldLine . type , oldLine . oldNumber , oldContent , oldPrefix ) ;
3860
+ fileHtml . right += that . generateSingleLineHtml ( isCombined , diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3834
3861
} else if ( newLine ) {
3835
- fileHtml . left += that . generateSingleLineHtml ( diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3836
- fileHtml . right += that . generateSingleLineHtml ( newLine . type , newLine . newNumber , newContent , newPrefix ) ;
3862
+ fileHtml . left += that . generateSingleLineHtml ( isCombined , diffParser . LINE_TYPE . CONTEXT , '' , '' , '' ) ;
3863
+ fileHtml . right += that . generateSingleLineHtml ( isCombined , newLine . type , newLine . newNumber , newContent , newPrefix ) ;
3837
3864
} else {
3838
3865
console . error ( 'How did it get here?' ) ;
3839
3866
}
@@ -3842,14 +3869,23 @@ process.umask = function() { return 0; };
3842
3869
return fileHtml ;
3843
3870
} ;
3844
3871
3845
- SideBySidePrinter . prototype . generateSingleLineHtml = function ( type , number , content , prefix ) {
3872
+ SideBySidePrinter . prototype . generateSingleLineHtml = function ( isCombined , type , number , content , possiblePrefix ) {
3873
+ var lineWithoutPrefix = content ;
3874
+ var prefix = possiblePrefix ;
3875
+
3876
+ if ( ! prefix ) {
3877
+ var lineWithPrefix = printerUtils . separatePrefix ( isCombined , content ) ;
3878
+ prefix = lineWithPrefix . prefix ;
3879
+ lineWithoutPrefix = lineWithPrefix . line ;
3880
+ }
3881
+
3846
3882
return hoganUtils . render ( genericTemplatesPath , 'line' ,
3847
3883
{
3848
3884
type : type ,
3849
3885
lineClass : 'd2h-code-side-linenumber' ,
3850
3886
contentClass : 'd2h-code-side-line' ,
3851
- prefix : prefix && utils . convertWhiteSpaceToNonBreakingSpace ( prefix ) ,
3852
- content : content && utils . convertWhiteSpaceToNonBreakingSpace ( content ) ,
3887
+ prefix : prefix ,
3888
+ content : lineWithoutPrefix ,
3853
3889
lineNumber : number
3854
3890
} ) ;
3855
3891
} ;
@@ -3908,10 +3944,6 @@ module.exports = global.browserTemplates;
3908
3944
function Utils ( ) {
3909
3945
}
3910
3946
3911
- Utils . prototype . convertWhiteSpaceToNonBreakingSpace = function ( str ) {
3912
- return str . slice ( 0 ) . replace ( / / g, ' ' ) ;
3913
- } ;
3914
-
3915
3947
Utils . prototype . escape = function ( str ) {
3916
3948
return str . slice ( 0 )
3917
3949
. replace ( / & / g, '&' )
0 commit comments