mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-09-10 17:01:26 +02:00
Fix commit expand button to not go to commit link (#8745)
* Fix commit expand button to not go to commit link * Fix message rendering to have correct HTML in result * Fix check for empty commit message * Code optimization
This commit is contained in:
parent
ac0fb36c41
commit
ebcc38188e
|
@ -19,6 +19,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
|
@ -338,34 +339,46 @@ func RenderCommitMessageLink(msg, urlPrefix, urlDefault string, metas map[string
|
||||||
// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to
|
// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to
|
||||||
// the provided default url, handling for special links without email to links.
|
// the provided default url, handling for special links without email to links.
|
||||||
func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
|
func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
|
||||||
cleanMsg := template.HTMLEscapeString(msg)
|
msgLine := strings.TrimLeftFunc(msg, unicode.IsSpace)
|
||||||
// we can safely assume that it will not return any error, since there
|
lineEnd := strings.IndexByte(msgLine, '\n')
|
||||||
// shouldn't be any special HTML.
|
if lineEnd > 0 {
|
||||||
fullMessage, err := markup.RenderCommitMessageSubject([]byte(cleanMsg), urlPrefix, urlDefault, metas)
|
msgLine = msgLine[:lineEnd]
|
||||||
if err != nil {
|
|
||||||
log.Error("RenderCommitMessageSubject: %v", err)
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
|
msgLine = strings.TrimRightFunc(msgLine, unicode.IsSpace)
|
||||||
if len(msgLines) == 0 {
|
if len(msgLine) == 0 {
|
||||||
return template.HTML("")
|
return template.HTML("")
|
||||||
}
|
}
|
||||||
return template.HTML(msgLines[0])
|
|
||||||
|
// we can safely assume that it will not return any error, since there
|
||||||
|
// shouldn't be any special HTML.
|
||||||
|
renderedMessage, err := markup.RenderCommitMessageSubject([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, urlDefault, metas)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("RenderCommitMessageSubject: %v", err)
|
||||||
|
return template.HTML("")
|
||||||
|
}
|
||||||
|
return template.HTML(renderedMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderCommitBody extracts the body of a commit message without its title.
|
// RenderCommitBody extracts the body of a commit message without its title.
|
||||||
func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
|
func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
|
||||||
cleanMsg := template.HTMLEscapeString(msg)
|
msgLine := strings.TrimRightFunc(msg, unicode.IsSpace)
|
||||||
fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
|
lineEnd := strings.IndexByte(msgLine, '\n')
|
||||||
|
if lineEnd > 0 {
|
||||||
|
msgLine = msgLine[lineEnd+1:]
|
||||||
|
} else {
|
||||||
|
return template.HTML("")
|
||||||
|
}
|
||||||
|
msgLine = strings.TrimLeftFunc(msgLine, unicode.IsSpace)
|
||||||
|
if len(msgLine) == 0 {
|
||||||
|
return template.HTML("")
|
||||||
|
}
|
||||||
|
|
||||||
|
renderedMessage, err := markup.RenderCommitMessage([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, "", metas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("RenderCommitMessage: %v", err)
|
log.Error("RenderCommitMessage: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
body := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
|
return template.HTML(renderedMessage)
|
||||||
if len(body) == 0 {
|
|
||||||
return template.HTML("")
|
|
||||||
}
|
|
||||||
return template.HTML(strings.Join(body[1:], "\n"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderNote renders the contents of a git-notes file as a commit message.
|
// RenderNote renders the contents of a git-notes file as a commit message.
|
||||||
|
|
|
@ -2994,7 +2994,8 @@ function initFilterBranchTagDropdown(selector) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".commit-button").click(function() {
|
$(".commit-button").click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
$(this).parent().find('.commit-body').toggle();
|
$(this).parent().find('.commit-body').toggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue