Skip to content

Commit c680eb2

Browse files
zeripath6543
andauthored
Links in markdown should be absolute to the repository not the server (#15088)
* Links in markdown should be absolute to the repository not the server Fix #15075 Signed-off-by: Andrew Thornton <[email protected]> * match github Signed-off-by: Andrew Thornton <[email protected]> * add testcase Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 84f5a0b commit c680eb2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

modules/markup/markdown/goldmark.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
9898
}
9999
prefix = strings.Replace(prefix, "/src/", "/media/", 1)
100100

101-
lnk := string(link)
101+
lnk := strings.TrimLeft(string(link), "/")
102+
102103
lnk = giteautil.URLJoin(prefix, lnk)
103104
link = []byte(lnk)
104105
}

modules/markup/markdown/markdown_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ func TestRender_Images(t *testing.T) {
9393
test(
9494
"[!["+title+"]("+url+")]("+href+")",
9595
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
96+
97+
url = "/../../.images/src/02/train.jpg"
98+
test(
99+
"!["+title+"]("+url+")",
100+
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
101+
102+
test(
103+
"[["+title+"|"+url+"]]",
104+
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" title="`+title+`" alt="`+title+`"/></a></p>`)
105+
test(
106+
"[!["+title+"]("+url+")]("+href+")",
107+
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)
108+
96109
}
97110

98111
func testAnswers(baseURLContent, baseURLImages string) []string {

0 commit comments

Comments
 (0)