Skip to content

Commit ebd88a5

Browse files
committed
fix commit subject DefaultLink
1 parent 526286b commit ebd88a5

File tree

7 files changed

+18
-43
lines changed

7 files changed

+18
-43
lines changed

modules/markup/html.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package markup
55

66
import (
77
"bytes"
8+
"fmt"
9+
"html/template"
810
"io"
911
"regexp"
1012
"strings"
@@ -196,13 +198,6 @@ func RenderCommitMessage(
196198
content string,
197199
) (string, error) {
198200
procs := commitMessageProcessors
199-
if ctx.DefaultLink != "" {
200-
// we don't have to fear data races, because being
201-
// commitMessageProcessors of fixed len and cap, every time we append
202-
// something to it the slice is realloc+copied, so append always
203-
// generates the slice ex-novo.
204-
procs = append(procs, genDefaultLinkProcessor(ctx.DefaultLink))
205-
}
206201
return renderProcessString(ctx, procs, content)
207202
}
208203

@@ -230,17 +225,17 @@ var emojiProcessors = []processor{
230225
// which changes every text node into a link to the passed default link.
231226
func RenderCommitMessageSubject(
232227
ctx *RenderContext,
233-
content string,
228+
defaultLink, content string,
234229
) (string, error) {
235230
procs := commitMessageSubjectProcessors
236-
if ctx.DefaultLink != "" {
237-
// we don't have to fear data races, because being
238-
// commitMessageSubjectProcessors of fixed len and cap, every time we
239-
// append something to it the slice is realloc+copied, so append always
240-
// generates the slice ex-novo.
241-
procs = append(procs, genDefaultLinkProcessor(ctx.DefaultLink))
231+
rendered, err := renderProcessString(ctx, procs, content)
232+
if err != nil {
233+
return "", err
242234
}
243-
return renderProcessString(ctx, procs, content)
235+
if defaultLink != "" {
236+
rendered = fmt.Sprintf(`<a href="%s" class="muted">%s</a>`, template.HTMLEscapeString(defaultLink), rendered)
237+
}
238+
return rendered, nil
244239
}
245240

246241
// RenderIssueTitle to process title on individual issue/pull page

modules/markup/html_link.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,6 @@ func linkProcessor(ctx *RenderContext, node *html.Node) {
200200
}
201201
}
202202

203-
func genDefaultLinkProcessor(defaultLink string) processor {
204-
return func(ctx *RenderContext, node *html.Node) {
205-
ch := &html.Node{
206-
Parent: node,
207-
Type: html.TextNode,
208-
Data: node.Data,
209-
}
210-
211-
node.Type = html.ElementNode
212-
node.Data = "a"
213-
node.DataAtom = atom.A
214-
node.Attr = []html.Attribute{
215-
{Key: "href", Val: defaultLink},
216-
{Key: "class", Val: "default-link muted"},
217-
}
218-
node.FirstChild, node.LastChild = ch, ch
219-
}
220-
}
221-
222203
// descriptionLinkProcessor creates links for DescriptionHTML
223204
func descriptionLinkProcessor(ctx *RenderContext, node *html.Node) {
224205
next := node.NextSibling

modules/markup/render.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type RenderContext struct {
5858
// markdownLineBreakStyle (comment, document)
5959
Metas map[string]string
6060

61-
DefaultLink string // TODO: need to figure out
6261
GitRepo *git.Repository
6362
Repo gitrepo.Repository
6463
ShaExistCache map[string]bool

modules/templates/util_render.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, me
6262
}
6363
msgLine = strings.TrimRightFunc(msgLine, unicode.IsSpace)
6464
if len(msgLine) == 0 {
65-
return template.HTML("")
65+
return ""
6666
}
6767

6868
// we can safely assume that it will not return any error, since there
6969
// shouldn't be any special HTML.
7070
renderedMessage, err := markup.RenderCommitMessageSubject(&markup.RenderContext{
71-
Ctx: ut.ctx,
72-
DefaultLink: urlDefault,
73-
Metas: metas,
74-
}, template.HTMLEscapeString(msgLine))
71+
Ctx: ut.ctx,
72+
Metas: metas,
73+
}, urlDefault, template.HTMLEscapeString(msgLine))
7574
if err != nil {
7675
log.Error("RenderCommitMessageSubject: %v", err)
77-
return template.HTML("")
76+
return ""
7877
}
7978
return renderCodeBlock(template.HTML(renderedMessage))
8079
}

modules/templates/util_render_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestRenderCommitMessage(t *testing.T) {
140140
}
141141

142142
func TestRenderCommitMessageLinkSubject(t *testing.T) {
143-
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" data-markdown-generated-content="" class="mention">@mention-user</a>`
143+
expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="" class="mention">@mention-user</a>`
144144
assert.EqualValues(t, expected, newTestRenderUtils().RenderCommitMessageLinkSubject(testInput(), "https://example.com/link", testMetas))
145145
}
146146

routers/common/markup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPa
5151
case "wiki":
5252
renderCtx.Metas = map[string]string{"markdownLineBreakStyle": "document", "markupContentMode": "wiki"}
5353
case "file":
54+
// render the repo file content by its extension
5455
renderCtx.Metas = map[string]string{"markdownLineBreakStyle": "document"}
5556
renderCtx.MarkupType = ""
5657
renderCtx.RelativePath = filePath

templates/repo/view_file.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div class="file-header-left tw-flex tw-items-center tw-py-2 tw-pr-4">
3030
{{if .ReadmeInList}}
3131
{{svg "octicon-book" 16 "tw-mr-2"}}
32-
<strong><a class="default-link muted" href="#readme">{{.FileName}}</a></strong>
32+
<strong><a class="muted" href="#readme">{{.FileName}}</a></strong>
3333
{{else}}
3434
{{template "repo/file_info" .}}
3535
{{end}}

0 commit comments

Comments
 (0)