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