@@ -5,15 +5,13 @@ package markup
55
66import (
77 "bytes"
8- "fmt"
9- "html/template"
108 "io"
119 "regexp"
10+ "slices"
1211 "strings"
1312 "sync"
1413
1514 "code.gitea.io/gitea/modules/markup/common"
16- "code.gitea.io/gitea/modules/setting"
1715
1816 "golang.org/x/net/html"
1917 "golang.org/x/net/html/atom"
@@ -85,12 +83,10 @@ var globalVars = sync.OnceValue[*globalVarsType](func() *globalVarsType {
8583 v .emojiShortCodeRegex = regexp .MustCompile (`:[-+\w]+:` )
8684
8785 // example: https://domain/org/repo/pulls/27#hash
88- v .issueFullPattern = regexp .MustCompile (regexp .QuoteMeta (setting .AppURL ) +
89- `[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b` )
86+ v .issueFullPattern = regexp .MustCompile (`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b` )
9087
9188 // example: https://domain/org/repo/pulls/27/files#hash
92- v .filesChangedFullPattern = regexp .MustCompile (regexp .QuoteMeta (setting .AppURL ) +
93- `[\w_.-]+/[\w_.-]+/pulls/((?:\w{1,10}-)?[1-9][0-9]*)/files([\?|#](\S+)?)?\b` )
89+ v .filesChangedFullPattern = regexp .MustCompile (`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/pulls/((?:\w{1,10}-)?[1-9][0-9]*)/files([\?|#](\S+)?)?\b` )
9490
9591 v .tagCleaner = regexp .MustCompile (`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))` )
9692 v .nulCleaner = strings .NewReplacer ("\000 " , "" )
@@ -227,15 +223,16 @@ func RenderCommitMessageSubject(
227223 ctx * RenderContext ,
228224 defaultLink , content string ,
229225) (string , error ) {
230- procs := commitMessageSubjectProcessors
231- rendered , err := renderProcessString (ctx , procs , content )
232- if err != nil {
233- return "" , err
234- }
235- if defaultLink != "" {
236- rendered = fmt .Sprintf (`<a href="%s" class="muted">%s</a>` , template .HTMLEscapeString (defaultLink ), rendered )
237- }
238- return rendered , nil
226+ procs := slices .Clone (commitMessageSubjectProcessors )
227+ procs = append (procs , func (ctx * RenderContext , node * html.Node ) {
228+ ch := & html.Node {Parent : node , Type : html .TextNode , Data : node .Data }
229+ node .Type = html .ElementNode
230+ node .Data = "a"
231+ node .DataAtom = atom .A
232+ node .Attr = []html.Attribute {{Key : "href" , Val : defaultLink }, {Key : "class" , Val : "muted" }}
233+ node .FirstChild , node .LastChild = ch , ch
234+ })
235+ return renderProcessString (ctx , procs , content )
239236}
240237
241238// RenderIssueTitle to process title on individual issue/pull page
0 commit comments