MCPcopy Create free account
hub / github.com/sergi/go-diff / DiffPrettyHtml

Method DiffPrettyHtml

diffmatchpatch/diff.go:1119–1139  ·  view source on GitHub ↗

DiffPrettyHtml converts a []Diff into a pretty HTML report. It is intended as an example from which to write one's own display functions.

(diffs []Diff)

Source from the content-addressed store, hash-verified

1117// DiffPrettyHtml converts a []Diff into a pretty HTML report.
1118// It is intended as an example from which to write one's own display functions.
1119func (dmp *DiffMatchPatch) DiffPrettyHtml(diffs []Diff) string {
1120 var buff bytes.Buffer
1121 for _, diff := range diffs {
1122 text := strings.Replace(html.EscapeString(diff.Text), "\n", "&para;<br>", -1)
1123 switch diff.Type {
1124 case DiffInsert:
1125 _, _ = buff.WriteString("<ins style=\"background:#e6ffe6;\">")
1126 _, _ = buff.WriteString(text)
1127 _, _ = buff.WriteString("</ins>")
1128 case DiffDelete:
1129 _, _ = buff.WriteString("<del style=\"background:#ffe6e6;\">")
1130 _, _ = buff.WriteString(text)
1131 _, _ = buff.WriteString("</del>")
1132 case DiffEqual:
1133 _, _ = buff.WriteString("<span>")
1134 _, _ = buff.WriteString(text)
1135 _, _ = buff.WriteString("</span>")
1136 }
1137 }
1138 return buff.String()
1139}
1140
1141// DiffPrettyText converts a []Diff into a colored text report.
1142func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {

Callers 1

TestDiffPrettyHtmlFunction · 0.80

Calls 1

StringMethod · 0.45

Tested by 1

TestDiffPrettyHtmlFunction · 0.64