File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,8 @@ func (hcd *highlightCodeDiff) convertToPlaceholders(htmlCode string) string {
169
169
hcd .placeholderOverflowCount ++
170
170
if strings .HasPrefix (token , "&" ) {
171
171
// when the token is a html entity, something must be outputted even if there is no placeholder.
172
- res .WriteRune (0xFFFD ) // replacement character TODO: how to handle this case more gracefully?
172
+ res .WriteRune (0xFFFD ) // replacement character TODO: how to handle this case more gracefully?
173
+ res .WriteString (token [1 :]) // still output the entity code part, otherwise there will be no diff result.
173
174
}
174
175
}
175
176
}
Original file line number Diff line number Diff line change @@ -63,7 +63,22 @@ func TestDiffWithHighlightPlaceholderExhausted(t *testing.T) {
63
63
`` ,
64
64
)
65
65
output := diffToHTML (nil , diffs , DiffLineDel )
66
- expected := fmt .Sprintf (`<span class="removed-code">%s</span>` , "\uFFFD " )
66
+ expected := fmt .Sprintf (`<span class="removed-code">%s#39;</span>` , "\uFFFD " )
67
+ assert .Equal (t , expected , output )
68
+
69
+ hcd = newHighlightCodeDiff ()
70
+ hcd .placeholderMaxCount = 0
71
+ diffs = hcd .diffWithHighlight (
72
+ "main.js" , "" ,
73
+ "a < b" ,
74
+ "a > b" ,
75
+ )
76
+ output = diffToHTML (nil , diffs , DiffLineDel )
77
+ expected = fmt .Sprintf (`a %s<span class="removed-code">l</span>t; b` , "\uFFFD " )
78
+ assert .Equal (t , expected , output )
79
+
80
+ output = diffToHTML (nil , diffs , DiffLineAdd )
81
+ expected = fmt .Sprintf (`a %s<span class="added-code">g</span>t; b` , "\uFFFD " )
67
82
assert .Equal (t , expected , output )
68
83
}
69
84
You can’t perform that action at this time.
0 commit comments