{{template "diff for at heading" .}}
-{{.Text}}
+ {{if .Text}}{{.Text}}{{else}}{{template "no text diff available" .}}{{end}}
diff --git a/history/histweb/histview.go b/history/histweb/histview.go index 4737817..1f59d77 100644 --- a/history/histweb/histview.go +++ b/history/histweb/histview.go @@ -11,6 +11,7 @@ import ( "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/viewutil" "github.com/gorilla/mux" + "html/template" "log" "net/http" "path/filepath" @@ -125,6 +126,7 @@ var ( {{define "diff for at title"}}Разница для {{beautifulName .HyphaName}} для {{.Hash}}{{end}} {{define "diff for at heading"}}Разница для {{beautifulName .HyphaName}} для {{.Hash}}{{end}} +{{define "no text diff available"}}Нет текстовой разницы.{{end}} {{define "count pre"}}Отобразить{{end}} {{define "count post"}}свежих правок.{{end}} @@ -158,15 +160,49 @@ type primitiveDiffData struct { *viewutil.BaseData HyphaName string Hash string - Text string + Text template.HTML } func primitiveDiff(meta viewutil.Meta, h hyphae.Hypha, hash, text string) { + hunks := history.SplitPrimitiveDiff(text) + if len(hunks) > 0 { + var buf strings.Builder + for _, hunk := range hunks { + lines := strings.Split(hunk, "\n") + buf.WriteString(`
`)
+ for i, line := range lines {
+ line = strings.Trim(line, "\r")
+ var class string
+ if len(line) > 0 {
+ switch line[0] {
+ case '+':
+ class = "primitive-diff__addition"
+ case '-':
+ class = "primitive-diff__deletion"
+ case '@':
+ class = "primitive-diff__context"
+ }
+ }
+ if i > 0 {
+ buf.WriteString("\n")
+ }
+ line = template.HTMLEscapeString(line)
+ fmt.Fprintf(&buf, `%s`,
+ class, line)
+ }
+ buf.WriteString(``)
+ }
+ text = buf.String()
+ } else if text != "" {
+ text = template.HTMLEscapeString(text)
+ text = fmt.Sprintf(
+ `%s`, text)
+ }
viewutil.ExecutePage(meta, chainPrimitiveDiff, primitiveDiffData{
BaseData: &viewutil.BaseData{},
HyphaName: h.CanonicalName(),
Hash: hash,
- Text: text,
+ Text: template.HTML(text),
})
}
diff --git a/history/histweb/view_primitive_diff.html b/history/histweb/view_primitive_diff.html
index c2025a0..135f41f 100644
--- a/history/histweb/view_primitive_diff.html
+++ b/history/histweb/view_primitive_diff.html
@@ -1,11 +1,12 @@
{{define "diff for at title"}}Diff of {{beautifulName .HyphaName}} at {{.Hash}}{{end}}
{{define "diff for at heading"}}Diff of {{beautifulName .HyphaName}} at {{.Hash}}{{end}}
+{{define "no text diff available"}}No text diff available.{{end}}
{{define "title"}}{{template "diff for at title" .}}{{end}}
{{define "body"}}
{{.Text}}
+ {{if .Text}}{{.Text}}{{else}}{{template "no text diff available" .}}{{end}}