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 <art27@cantab.net> * match github Signed-off-by: Andrew Thornton <art27@cantab.net> * add testcase Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		
							parent
							
								
									84f5a0bc62
								
							
						
					
					
						commit
						c680eb2cc7
					
				
					 2 changed files with 15 additions and 1 deletions
				
			
		|  | @ -98,7 +98,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa | ||||||
| 				} | 				} | ||||||
| 				prefix = strings.Replace(prefix, "/src/", "/media/", 1) | 				prefix = strings.Replace(prefix, "/src/", "/media/", 1) | ||||||
| 
 | 
 | ||||||
| 				lnk := string(link) | 				lnk := strings.TrimLeft(string(link), "/") | ||||||
|  | 
 | ||||||
| 				lnk = giteautil.URLJoin(prefix, lnk) | 				lnk = giteautil.URLJoin(prefix, lnk) | ||||||
| 				link = []byte(lnk) | 				link = []byte(lnk) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -93,6 +93,19 @@ func TestRender_Images(t *testing.T) { | ||||||
| 	test( | 	test( | ||||||
| 		"[]("+href+")", | 		"[]("+href+")", | ||||||
| 		`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`) | 		`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`) | ||||||
|  | 
 | ||||||
|  | 	url = "/../../.images/src/02/train.jpg" | ||||||
|  | 	test( | ||||||
|  | 		"", | ||||||
|  | 		`<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( | ||||||
|  | 		"[]("+href+")", | ||||||
|  | 		`<p><a href="`+href+`" rel="nofollow"><img src="`+result+`" alt="`+title+`"/></a></p>`) | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func testAnswers(baseURLContent, baseURLImages string) []string { | func testAnswers(baseURLContent, baseURLImages string) []string { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue