Skip to content

Commit ef0c4a2

Browse files
KN4CK3RGiteaBot
andcommitted
Respect branch info for relative links (go-gitea#28909)
Fix go-gitea#28904 Co-authored-by: Giteabot <[email protected]>
1 parent e950068 commit ef0c4a2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

modules/markup/markdown/goldmark.go

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
137137
var base string
138138
if ctx.IsWiki {
139139
base = ctx.Links.WikiLink()
140+
} else if ctx.Links.HasBranchInfo() {
141+
base = ctx.Links.SrcLink()
140142
} else {
141143
base = ctx.Links.Base
142144
}

modules/markup/markdown/markdown_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ space</p>
765765
Expected: `<p>space @mention-user<br/>
766766
/just/a/path.bin<br/>
767767
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
768-
<a href="/user/repo/file.bin" rel="nofollow">local link</a><br/>
768+
<a href="/user/repo/src/branch/main/file.bin" rel="nofollow">local link</a><br/>
769769
<a href="https://example.com" rel="nofollow">remote link</a><br/>
770770
<a href="/user/repo/src/branch/main/file.bin" rel="nofollow">local link</a><br/>
771771
<a href="https://example.com" rel="nofollow">remote link</a><br/>
@@ -878,7 +878,7 @@ space</p>
878878
Expected: `<p>space @mention-user<br/>
879879
/just/a/path.bin<br/>
880880
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
881-
<a href="/user/repo/file.bin" rel="nofollow">local link</a><br/>
881+
<a href="/user/repo/src/branch/main/sub/folder/file.bin" rel="nofollow">local link</a><br/>
882882
<a href="https://example.com" rel="nofollow">remote link</a><br/>
883883
<a href="/user/repo/src/branch/main/sub/folder/file.bin" rel="nofollow">local link</a><br/>
884884
<a href="https://example.com" rel="nofollow">remote link</a><br/>

0 commit comments

Comments
 (0)