Skip to content

Commit

Permalink
Links in markdown should be absolute to the repository not the server (
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
zeripath and 6543 authored Apr 10, 2021
1 parent 84f5a0b commit c680eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/markup/markdown/goldmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
}
prefix = strings.Replace(prefix, "/src/", "/media/", 1)

lnk := string(link)
lnk := strings.TrimLeft(string(link), "/")

lnk = giteautil.URLJoin(prefix, lnk)
link = []byte(lnk)
}
Expand Down
13 changes: 13 additions & 0 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ func TestRender_Images(t *testing.T) {
test(
"[!["+title+"]("+url+")]("+href+")",
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)

url = "/../../.images/src/02/train.jpg"
test(
"!["+title+"]("+url+")",
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)

test(
"[["+title+"|"+url+"]]",
`<p><a href="`+result+`" rel="nofollow"><img src="`+result+`" title="`+title+`" alt="`+title+`"/></a></p>`)
test(
"[!["+title+"]("+url+")]("+href+")",
`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`)

}

func testAnswers(baseURLContent, baseURLImages string) []string {
Expand Down

0 comments on commit c680eb2

Please sign in to comment.