diff options
author | Unknwon <u@gogs.io> | 2015-12-06 20:06:23 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-06 20:06:23 -0500 |
commit | abb02889f21b021b826e62999947c895e4d9c3a4 (patch) | |
tree | f3815745e988911a34edb7524b69048ee4f9c17c /modules | |
parent | b5f6206a659eaa76382774675f2e3f2664d0f501 (diff) | |
parent | e2ca53029e0c4c28c0796d3d55bfecf28c132d2e (diff) |
Merge pull request #2112 from nanoant/patch/better-git-message-display
Render commit msg as header + verbatim description
Diffstat (limited to 'modules')
-rw-r--r-- | modules/template/template.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/template/template.go b/modules/template/template.go index d0d77b01..9d63452d 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -183,15 +183,27 @@ func ReplaceLeft(s, old, new string) string { } // RenderCommitMessage renders commit message with XSS-safe and special links. -func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML { +func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) template.HTML { cleanMsg := template.HTMLEscapeString(msg) fullMessage := string(base.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix, metas)) msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") - for i := range msgLines { - msgLines[i] = ReplaceLeft(msgLines[i], " ", " ") + numLines := len(msgLines) + if numLines == 0 { + return template.HTML("") + } else if !full { + return template.HTML(msgLines[0]) + } else if numLines == 1 || (numLines >= 2 && len(msgLines[1]) == 0) { + // First line is a header, standalone or followed by empty line + header := fmt.Sprintf("<h3>%s</h3>", msgLines[0]) + if numLines >= 2 { + fullMessage = header + fmt.Sprintf("\n<pre>%s</pre>", strings.Join(msgLines[2:], "\n")) + } else { + fullMessage = header + } + } else { + // Non-standard git message, there is no header line + fullMessage = fmt.Sprintf("<h4>%s</h4>", strings.Join(msgLines, "<br>")) } - - fullMessage = strings.Join(msgLines, "<br>") return template.HTML(fullMessage) } |