diff options
author | jaqra <48099350+jaqra@users.noreply.github.com> | 2019-09-10 12:03:30 +0300 |
---|---|---|
committer | Lauris BH <lauris.buksis@zzdats.lv> | 2019-09-10 12:03:30 +0300 |
commit | 7e17424c7e189f91d4f1b35e2504141b1e8116f6 (patch) | |
tree | f5d0711fa6f368b9aa751113b4ee868d281e803a /modules/templates | |
parent | 7eacdcf39a4de3a5ea2f234f9444753ee40d8d35 (diff) | |
download | gitea-7e17424c7e189f91d4f1b35e2504141b1e8116f6.tar.gz gitea-7e17424c7e189f91d4f1b35e2504141b1e8116f6.zip |
Make link last commit massages in repository home page and commit tables (#8006)
* Make link last commit massages in repository home page and commit tables
* Use RenderCommitMessageLink instead surround with a
* deleted __debug_bin file
* Exclude email to link from latest commit title
* Exclude email processor from commit table
Co-Authored-By: mrsdizzie <info@mrsdizzie.com>
* Add class parameter to a html element creator functions.
Make links underline dashed that are not commit
* fix tests
* Show dashed underline when also not hovered
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 147df3a788..ba61dd5eef 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -118,13 +118,14 @@ func NewFuncMap() []template.FuncMap { "EscapePound": func(str string) string { return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str) }, - "PathEscapeSegments": util.PathEscapeSegments, - "URLJoin": util.URLJoin, - "RenderCommitMessage": RenderCommitMessage, - "RenderCommitMessageLink": RenderCommitMessageLink, - "RenderCommitBody": RenderCommitBody, - "RenderNote": RenderNote, - "IsMultilineCommitMessage": IsMultilineCommitMessage, + "PathEscapeSegments": util.PathEscapeSegments, + "URLJoin": util.URLJoin, + "RenderCommitMessage": RenderCommitMessage, + "RenderCommitMessageLink": RenderCommitMessageLink, + "RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject, + "RenderCommitBody": RenderCommitBody, + "RenderNote": RenderNote, + "IsMultilineCommitMessage": IsMultilineCommitMessage, "ThemeColorMetaTag": func() string { return setting.UI.ThemeColorMetaTag }, @@ -322,6 +323,24 @@ func RenderCommitMessageLink(msg, urlPrefix, urlDefault string, metas map[string return template.HTML(msgLines[0]) } +// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to +// the provided default url, handling for special links without email to links. +func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML { + cleanMsg := template.HTMLEscapeString(msg) + // we can safely assume that it will not return any error, since there + // shouldn't be any special HTML. + fullMessage, err := markup.RenderCommitMessageSubject([]byte(cleanMsg), urlPrefix, urlDefault, metas) + if err != nil { + log.Error("RenderCommitMessageSubject: %v", err) + return "" + } + msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n") + if len(msgLines) == 0 { + return template.HTML("") + } + 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 { cleanMsg := template.HTMLEscapeString(msg) |