@@ -153,18 +153,31 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
153153 link = []byte (util .URLJoin (r .URLPrefix , lnk ))
154154 }
155155
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
160157 switch l .Kind () {
161158 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+ }
164167 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+ }
167176 default :
177+ description := string (link )
178+ if l .Description != nil {
179+ description = r .WriteNodesAsString (l .Description ... )
180+ }
168181 fmt .Fprintf (r , `<a href="%s" title="%s">%s</a>` , link , description , description )
169182 }
170183}
0 commit comments