File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 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 {
169169 hcd .placeholderOverflowCount ++
170170 if strings .HasPrefix (token , "&" ) {
171171 // 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.
173174 }
174175 }
175176 }
Original file line number Diff line number Diff line change @@ -63,7 +63,22 @@ func TestDiffWithHighlightPlaceholderExhausted(t *testing.T) {
6363 `` ,
6464 )
6565 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 " )
6782 assert .Equal (t , expected , output )
6883}
6984
You can’t perform that action at this time.
0 commit comments