aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 2b9e593360..42e465aeaa 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -110,8 +110,10 @@ func NewFuncMap() []template.FuncMap {
"EscapePound": func(str string) string {
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
},
- "RenderCommitMessage": RenderCommitMessage,
- "RenderCommitMessageLink": RenderCommitMessageLink,
+ "RenderCommitMessage": RenderCommitMessage,
+ "RenderCommitMessageLink": RenderCommitMessageLink,
+ "RenderCommitBody": RenderCommitBody,
+ "IsMultilineCommitMessage": IsMultilineCommitMessage,
"ThemeColorMetaTag": func() string {
return setting.UI.ThemeColorMetaTag
},
@@ -280,6 +282,29 @@ func renderCommitMessage(msg string, opts markup.RenderIssueIndexPatternOptions)
return template.HTML(msgLines[0])
}
+// RenderCommitBody extracts the body of a commit message without its title.
+func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
+ return renderCommitBody(msg, markup.RenderIssueIndexPatternOptions{
+ URLPrefix: urlPrefix,
+ Metas: metas,
+ })
+}
+
+func renderCommitBody(msg string, opts markup.RenderIssueIndexPatternOptions) template.HTML {
+ cleanMsg := template.HTMLEscapeString(msg)
+ fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), opts))
+ body := strings.Split(strings.TrimSpace(fullMessage), "\n")
+ if len(body) == 0 {
+ return template.HTML("")
+ }
+ return template.HTML(strings.Join(body[1:], "\n"))
+}
+
+// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
+func IsMultilineCommitMessage(msg string) bool {
+ return strings.Count(strings.TrimSpace(msg), "\n") > 1
+}
+
// Actioner describes an action
type Actioner interface {
GetOpType() models.ActionType