@@ -153,18 +153,31 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
153
153
link = []byte (util .URLJoin (r .URLPrefix , lnk ))
154
154
}
155
155
156
- description := string (link )
157
- if l .Description != nil {
158
- description = r .WriteNodesAsString (l .Description ... )
159
- }
156
+ // Inspired by https://github.com/niklasfasching/go-org/blob/6eb20dbda93cb88c3503f7508dc78cbbc639378f/org/html_writer.go#L406-L427
160
157
switch l .Kind () {
161
158
case "image" :
162
- imageSrc := getMediaURL (link )
163
- fmt .Fprintf (r , `<img src="%s" alt="%s" title="%s" />` , imageSrc , description , description )
159
+ if l .Description == nil {
160
+ imageSrc := getMediaURL (link )
161
+ fmt .Fprintf (r , `<img src="%s" alt="%s" title="%s" />` , imageSrc , link , link )
162
+ } else {
163
+ description := strings .TrimPrefix (org .String (l .Description ... ), "file:" )
164
+ imageSrc := getMediaURL ([]byte (description ))
165
+ fmt .Fprintf (r , `<a href="%s"><img src="%s" alt="%s" /></a>` , link , imageSrc , imageSrc )
166
+ }
164
167
case "video" :
165
- videoSrc := getMediaURL (link )
166
- fmt .Fprintf (r , `<video src="%s" title="%s">%s</video>` , videoSrc , description , description )
168
+ if l .Description == nil {
169
+ imageSrc := getMediaURL (link )
170
+ fmt .Fprintf (r , `<video src="%s" title="%s">%s</video>` , imageSrc , link , link )
171
+ } else {
172
+ description := strings .TrimPrefix (org .String (l .Description ... ), "file:" )
173
+ videoSrc := getMediaURL ([]byte (description ))
174
+ fmt .Fprintf (r , `<a href="%s"><video src="%s" title="%s"></video></a>` , link , videoSrc , videoSrc )
175
+ }
167
176
default :
177
+ description := string (link )
178
+ if l .Description != nil {
179
+ description = r .WriteNodesAsString (l .Description ... )
180
+ }
168
181
fmt .Fprintf (r , `<a href="%s" title="%s">%s</a>` , link , description , description )
169
182
}
170
183
}
0 commit comments