@@ -283,12 +283,12 @@ func DiffInlineWithHighlightCode(fileName, language, code string) DiffInline {
283
283
return DiffInline {EscapeStatus : status , Content : template .HTML (content )}
284
284
}
285
285
286
- // HighlightCodeDiff is used to do diff with highlighted HTML code.
286
+ // highlightCodeDiff is used to do diff with highlighted HTML code.
287
287
// The HTML tags will be replaced by Unicode placeholders: "<span>{TEXT}</span>" => "\uE000{TEXT}\uE001"
288
288
// These Unicode placeholders are friendly to the diff.
289
289
// Then after diff, the placeholders in diff result will be recovered to the HTML tags.
290
290
// It's guaranteed that the tags in final diff result are paired correctly.
291
- type HighlightCodeDiff struct {
291
+ type highlightCodeDiff struct {
292
292
placeholderBegin rune
293
293
placeholderMaxCount int
294
294
placeholderIndex int
@@ -298,8 +298,8 @@ type HighlightCodeDiff struct {
298
298
lineWrapperTags []string
299
299
}
300
300
301
- func NewHighlightCodeDiff () * HighlightCodeDiff {
302
- return & HighlightCodeDiff {
301
+ func newHighlightCodeDiff () * highlightCodeDiff {
302
+ return & highlightCodeDiff {
303
303
placeholderBegin : rune (0xE000 ), // Private Use Unicode: U+E000..U+F8FF, BMP(0), 6400
304
304
placeholderMaxCount : 6400 ,
305
305
placeholderTagMap : map [rune ]string {},
@@ -310,7 +310,7 @@ func NewHighlightCodeDiff() *HighlightCodeDiff {
310
310
// nextPlaceholder returns 0 if no more placeholder can be used
311
311
// the diff is done line by line, usually there are only a few (no more than 10) placeholders in one line
312
312
// so the placeholderMaxCount is impossible to be exhausted in real cases.
313
- func (hcd * HighlightCodeDiff ) nextPlaceholder () rune {
313
+ func (hcd * highlightCodeDiff ) nextPlaceholder () rune {
314
314
for hcd .placeholderIndex < hcd .placeholderMaxCount {
315
315
r := hcd .placeholderBegin + rune (hcd .placeholderIndex )
316
316
hcd .placeholderIndex ++
@@ -322,11 +322,11 @@ func (hcd *HighlightCodeDiff) nextPlaceholder() rune {
322
322
return 0 // no more available placeholder
323
323
}
324
324
325
- func (hcd * HighlightCodeDiff ) isInPlaceholderRange (r rune ) bool {
325
+ func (hcd * highlightCodeDiff ) isInPlaceholderRange (r rune ) bool {
326
326
return hcd .placeholderBegin <= r && r < hcd .placeholderBegin + rune (hcd .placeholderMaxCount )
327
327
}
328
328
329
- func (hcd * HighlightCodeDiff ) collectUsedRunes (code string ) {
329
+ func (hcd * highlightCodeDiff ) collectUsedRunes (code string ) {
330
330
for _ , r := range code {
331
331
if hcd .isInPlaceholderRange (r ) {
332
332
// put the existing rune (used by code) in map, then this rune won't be used a placeholder anymore.
@@ -335,7 +335,7 @@ func (hcd *HighlightCodeDiff) collectUsedRunes(code string) {
335
335
}
336
336
}
337
337
338
- func (hcd * HighlightCodeDiff ) diffWithHighlight (filename , language , codeA , codeB string ) []diffmatchpatch.Diff {
338
+ func (hcd * highlightCodeDiff ) diffWithHighlight (filename , language , codeA , codeB string ) []diffmatchpatch.Diff {
339
339
hcd .collectUsedRunes (codeA )
340
340
hcd .collectUsedRunes (codeB )
341
341
@@ -354,7 +354,7 @@ func (hcd *HighlightCodeDiff) diffWithHighlight(filename, language, codeA, codeB
354
354
return diffs
355
355
}
356
356
357
- func (hcd * HighlightCodeDiff ) convertToPlaceholders (htmlCode string ) string {
357
+ func (hcd * highlightCodeDiff ) convertToPlaceholders (htmlCode string ) string {
358
358
var tagStack []string
359
359
res := strings.Builder {}
360
360
@@ -419,7 +419,7 @@ func (hcd *HighlightCodeDiff) convertToPlaceholders(htmlCode string) string {
419
419
return res .String ()
420
420
}
421
421
422
- func (hcd * HighlightCodeDiff ) recoverOneDiff (diff * diffmatchpatch.Diff ) {
422
+ func (hcd * highlightCodeDiff ) recoverOneDiff (diff * diffmatchpatch.Diff ) {
423
423
sb := strings.Builder {}
424
424
var tagStack []string
425
425
@@ -501,7 +501,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) Dif
501
501
return DiffInlineWithHighlightCode (diffSection .FileName , language , diffLine .Content )
502
502
}
503
503
504
- hcd := NewHighlightCodeDiff ()
504
+ hcd := newHighlightCodeDiff ()
505
505
diffRecord := hcd .diffWithHighlight (diffSection .FileName , language , diff1 [1 :], diff2 [1 :])
506
506
// it seems that Gitea doesn't need the line wrapper of Chroma, so do not add them back
507
507
// if the line wrappers are still needed in the future, it can be added back by "diffToHTML(hcd.lineWrapperTags. ...)"
0 commit comments