diff options
author | mrsdizzie <info@mrsdizzie.com> | 2020-07-11 01:43:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-11 13:43:12 +0800 |
commit | 8d081950e61d8f3d43544d566e810b448e8516a6 (patch) | |
tree | a59e00786162c05efa7202ba360e1d1adca1f688 /services/gitdiff | |
parent | 6a62884782b29653bcd4462188e263018e5e21e8 (diff) | |
download | gitea-8d081950e61d8f3d43544d566e810b448e8516a6.tar.gz gitea-8d081950e61d8f3d43544d566e810b448e8516a6.zip |
Ensure syntax highlighting is the same inside diffs (#12205)
Make sure to end up with the same syntax highlighting inside various sections of diffs by processing the code first before detecting specific changes between the lines. Also try and make sure that when highlighting individual lines in a diff that it is tokenized the same as it would be when part of an entire file with more context.
Fixes: #12190
Diffstat (limited to 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index d335661ffb..7d08f63eb7 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -188,14 +188,14 @@ func diffToHTML(fileName string, diffs []diffmatchpatch.Diff, lineType DiffLineT switch { case diffs[i].Type == diffmatchpatch.DiffInsert && lineType == DiffLineAdd: buf.Write(addedCodePrefix) - buf.WriteString(highlight.Code(fileName, diffs[i].Text)) + buf.WriteString(getLineContent(diffs[i].Text)) buf.Write(codeTagSuffix) case diffs[i].Type == diffmatchpatch.DiffDelete && lineType == DiffLineDel: buf.Write(removedCodePrefix) - buf.WriteString(highlight.Code(fileName, diffs[i].Text)) + buf.WriteString(getLineContent(diffs[i].Text)) buf.Write(codeTagSuffix) case diffs[i].Type == diffmatchpatch.DiffEqual: - buf.WriteString(highlight.Code(fileName, getLineContent(diffs[i].Text))) + buf.WriteString(getLineContent(diffs[i].Text)) } } return template.HTML(buf.Bytes()) @@ -287,7 +287,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem return template.HTML(highlight.Code(diffSection.FileName, diffLine.Content)) } - diffRecord := diffMatchPatch.DiffMain(diff1[1:], diff2[1:], true) + diffRecord := diffMatchPatch.DiffMain(highlight.Code(diffSection.FileName, diff1[1:]), highlight.Code(diffSection.FileName, diff2[1:]), true) diffRecord = diffMatchPatch.DiffCleanupEfficiency(diffRecord) return diffToHTML(diffSection.FileName, diffRecord, diffLine.Type) } |