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

Method DiffPrettyHtml

diffmatchpatch/diff.go:1136–1156  ·  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

1134// DiffPrettyHtml converts a []Diff into a pretty HTML report.
1135// It is intended as an example from which to write one's own display functions.
1136func (dmp *DiffMatchPatch) DiffPrettyHtml(diffs []Diff) string {
1137 var buff bytes.Buffer
1138 for _, diff := range diffs {
1139 text := strings.Replace(html.EscapeString(diff.Text), "\n", "&para;<br>", -1)
1140 switch diff.Type {
1141 case DiffInsert:
1142 _, _ = buff.WriteString("<ins style=\"background:#e6ffe6;\">")
1143 _, _ = buff.WriteString(text)
1144 _, _ = buff.WriteString("</ins>")
1145 case DiffDelete:
1146 _, _ = buff.WriteString("<del style=\"background:#ffe6e6;\">")
1147 _, _ = buff.WriteString(text)
1148 _, _ = buff.WriteString("</del>")
1149 case DiffEqual:
1150 _, _ = buff.WriteString("<span>")
1151 _, _ = buff.WriteString(text)
1152 _, _ = buff.WriteString("</span>")
1153 }
1154 }
1155 return buff.String()
1156}
1157
1158// DiffPrettyText converts a []Diff into a colored text report.
1159func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {

Callers 1

TestDiffPrettyHtmlFunction · 0.80

Calls 1

StringMethod · 0.45

Tested by 1

TestDiffPrettyHtmlFunction · 0.64