@@ -38,7 +38,16 @@ func (r *Renderer) Link(out *bytes.Buffer, link []byte, title []byte, content []
38
38
link = []byte (mLink )
39
39
}
40
40
41
- r .Renderer .Link (out , link , title , content )
41
+ if len (content ) > 10 && string (content [0 :9 ]) == "<a href=\" " && bytes .Contains (content [9 :], []byte ("<img" )) {
42
+ // Image with link case: markdown `[![]()]()`
43
+ // If the content is an image, then we change the original href around it
44
+ // which points to itself to a new address "link"
45
+ rightQuote := bytes .Index (content [9 :], []byte ("\" " ))
46
+ content = bytes .Replace (content , content [9 :9 + rightQuote ], link , 1 )
47
+ out .Write (content )
48
+ } else {
49
+ r .Renderer .Link (out , link , title , content )
50
+ }
42
51
}
43
52
44
53
// List renders markdown bullet or digit lists to HTML
@@ -104,22 +113,14 @@ func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byt
104
113
prefix = util .URLJoin (prefix , "wiki" , "raw" )
105
114
}
106
115
prefix = strings .Replace (prefix , "/src/" , "/raw/" , 1 )
107
- if len (link ) > 0 {
108
- if markup .IsLink (link ) {
109
- // External link with .svg suffix usually means CI status.
110
- // TODO: define a keyword to allow non-svg images render as external link.
111
- if bytes .HasSuffix (link , svgSuffix ) || bytes .Contains (link , svgSuffixWithMark ) {
112
- r .Renderer .Image (out , link , title , alt )
113
- return
114
- }
115
- } else {
116
- lnk := string (link )
117
- lnk = util .URLJoin (prefix , lnk )
118
- lnk = strings .Replace (lnk , " " , "+" , - 1 )
119
- link = []byte (lnk )
120
- }
116
+ if len (link ) > 0 && ! markup .IsLink (link ) {
117
+ lnk := string (link )
118
+ lnk = util .URLJoin (prefix , lnk )
119
+ lnk = strings .Replace (lnk , " " , "+" , - 1 )
120
+ link = []byte (lnk )
121
121
}
122
122
123
+ // Put a link around it pointint to ifself by default
123
124
out .WriteString (`<a href="` )
124
125
out .Write (link )
125
126
out .WriteString (`">` )
0 commit comments