@@ -5,16 +5,13 @@ package markup
5
5
6
6
import (
7
7
"bytes"
8
- "fmt"
9
- "html/template"
10
8
"io"
11
9
"regexp"
10
+ "slices"
12
11
"strings"
13
12
"sync"
14
13
15
14
"code.gitea.io/gitea/modules/markup/common"
16
- "code.gitea.io/gitea/modules/setting"
17
-
18
15
"golang.org/x/net/html"
19
16
"golang.org/x/net/html/atom"
20
17
"mvdan.cc/xurls/v2"
@@ -85,12 +82,10 @@ var globalVars = sync.OnceValue[*globalVarsType](func() *globalVarsType {
85
82
v .emojiShortCodeRegex = regexp .MustCompile (`:[-+\w]+:` )
86
83
87
84
// 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` )
85
+ v .issueFullPattern = regexp .MustCompile (`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#](\S+)?)?\b` )
90
86
91
87
// 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` )
88
+ v .filesChangedFullPattern = regexp .MustCompile (`https?://(?:\S+/)[\w_.-]+/[\w_.-]+/pulls/((?:\w{1,10}-)?[1-9][0-9]*)/files([\?|#](\S+)?)?\b` )
94
89
95
90
v .tagCleaner = regexp .MustCompile (`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))` )
96
91
v .nulCleaner = strings .NewReplacer ("\000 " , "" )
@@ -227,15 +222,16 @@ func RenderCommitMessageSubject(
227
222
ctx * RenderContext ,
228
223
defaultLink , content string ,
229
224
) (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
225
+ procs := slices .Clone (commitMessageSubjectProcessors )
226
+ procs = append (procs , func (ctx * RenderContext , node * html.Node ) {
227
+ ch := & html.Node {Parent : node , Type : html .TextNode , Data : node .Data }
228
+ node .Type = html .ElementNode
229
+ node .Data = "a"
230
+ node .DataAtom = atom .A
231
+ node .Attr = []html.Attribute {{Key : "href" , Val : defaultLink }, {Key : "class" , Val : "muted" }}
232
+ node .FirstChild , node .LastChild = ch , ch
233
+ })
234
+ return renderProcessString (ctx , procs , content )
239
235
}
240
236
241
237
// RenderIssueTitle to process title on individual issue/pull page
0 commit comments