Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7850972
Improve code highlight
wxiaoguang Jun 13, 2022
ca6a537
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 13, 2022
f0e2f97
remove unnecessary code, add more comments
wxiaoguang Jun 13, 2022
ec8da9e
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 13, 2022
de042fc
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 14, 2022
62eb155
clear edge cases, fine tune tests
wxiaoguang Jun 14, 2022
bb64dff
remove line wrapper tags when doing highlight code diff
wxiaoguang Jun 15, 2022
9b183f5
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 15, 2022
f172f88
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 15, 2022
6226d38
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 17, 2022
adaf320
fine tune
wxiaoguang Jun 17, 2022
9b5b079
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 17, 2022
4aa94e8
Update services/gitdiff/gitdiff.go
wxiaoguang Jun 17, 2022
17e0660
Merge branch 'main' into fix-code-highlight
lunny Jun 18, 2022
77445c2
fine tune comments
wxiaoguang Jun 18, 2022
6b359d9
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 18, 2022
9953e09
Merge branch 'main' into fix-code-highlight
wxiaoguang Jun 18, 2022
5fc6801
Merge branch 'main' into fix-code-highlight
lunny Jun 18, 2022
57f7bf8
Merge branch 'main' into fix-code-highlight
lunny Jun 27, 2022
47030f1
Merge branch 'main' into fix-code-highlight
lafriks Jun 27, 2022
27c78e1
Merge branch 'main' into fix-code-highlight
zeripath Jul 6, 2022
df5fef8
Update gitdiff.go
wxiaoguang Jul 7, 2022
843579a
Update gitdiff.go
wxiaoguang Jul 7, 2022
2e798d8
Update gitdiff.go
wxiaoguang Jul 7, 2022
ece0e3f
more tests
wxiaoguang Jul 9, 2022
c9a1566
private function & private struct
wxiaoguang Jul 9, 2022
f21f422
demo for why the tags are all closed
wxiaoguang Jul 9, 2022
3c2aa66
add comment
wxiaoguang Jul 9, 2022
90c6440
placeholder for html entity
wxiaoguang Jul 9, 2022
dc74baf
fine tune comments
wxiaoguang Jul 9, 2022
4afb1cc
always output the code/name part of the html entities if the placehol…
wxiaoguang Jul 9, 2022
4d1d8a4
fine tune comments
wxiaoguang Jul 9, 2022
9cf358b
demo why the tags are always balanced
wxiaoguang Jul 9, 2022
e6215ae
Merge branch 'main' into fix-code-highlight
wxiaoguang Jul 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
demo for why the tags are all closed
  • Loading branch information
wxiaoguang committed Jul 9, 2022
commit f21f422baf56f32a9b6656eacd056ebdc7ad4c62
8 changes: 6 additions & 2 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ type highlightCodeDiff struct {
placeholderTagMap map[rune]string
tagPlaceholderMap map[string]rune

placeholderOverflowCount int

lineWrapperTags []string
}

Expand Down Expand Up @@ -410,9 +412,11 @@ func (hcd *highlightCodeDiff) convertToPlaceholders(htmlCode string) string {

if placeholder != 0 {
res.WriteRune(placeholder) // use the placeholder to replace the tag
} else {
// unfortunately, all private use runes has been exhausted, no more placeholder could be used, no more converting
// usually, the exhausting won't occur in real cases, the magnitude of used placeholders is not larger than that of the CSS classes outputted by chroma.
hcd.placeholderOverflowCount++
}
// else: unfortunately, all private use runes has been exhausted, no more placeholder could be used, no more converting
// usually, the exhausting won't occur in real cases, the magnitude of used placeholders is not larger than that of the CSS classes outputted by chroma.
}
// write the remaining string
res.WriteString(htmlCode)
Expand Down
23 changes: 23 additions & 0 deletions services/gitdiff/gitdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,29 @@ func TestDiffWithHighlightPlaceholder(t *testing.T) {
expected = fmt.Sprintf(`<span class="nx">a</span><span class="o">=</span><span class="s1">&#39;</span><span class="added-code">%s</span>&#39;`, "\uF8FF")
output = diffToHTML(nil, diffs, DiffLineAdd)
assert.Equal(t, expected, output)

totalOverflow := 0
for i := 0; i < 100; i++ {
hcd = newHighlightCodeDiff()
hcd.placeholderMaxCount = i
diffs = hcd.diffWithHighlight(
"main.js", "",
"a='1'",
"b='2'",
)
totalOverflow += hcd.placeholderOverflowCount

output = diffToHTML(nil, diffs, DiffLineDel)
c1 := strings.Count(output, "<span")
c2 := strings.Count(output, "</span")
assert.Equal(t, c1, c2)

output = diffToHTML(nil, diffs, DiffLineAdd)
c1 = strings.Count(output, "<span")
c2 = strings.Count(output, "</span")
assert.Equal(t, c1, c2)
}
assert.NotZero(t, totalOverflow)
}

func TestNoCrashes(t *testing.T) {
Expand Down