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)
| 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. |
| 1119 | func (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", "¶<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. |
| 1142 | func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string { |