summaryrefslogtreecommitdiffstats
path: root/modules/markup/orgmode/orgmode.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markup/orgmode/orgmode.go')
-rw-r--r--modules/markup/orgmode/orgmode.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go
index a6dac12039..9b6175649f 100644
--- a/modules/markup/orgmode/orgmode.go
+++ b/modules/markup/orgmode/orgmode.go
@@ -153,18 +153,31 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
link = []byte(util.URLJoin(r.URLPrefix, lnk))
}
- description := string(link)
- if l.Description != nil {
- description = r.WriteNodesAsString(l.Description...)
- }
+ // Inspired by https://github.com/niklasfasching/go-org/blob/6eb20dbda93cb88c3503f7508dc78cbbc639378f/org/html_writer.go#L406-L427
switch l.Kind() {
case "image":
- imageSrc := getMediaURL(link)
- fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, description, description)
+ if l.Description == nil {
+ imageSrc := getMediaURL(link)
+ fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link)
+ } else {
+ description := strings.TrimPrefix(org.String(l.Description...), "file:")
+ imageSrc := getMediaURL([]byte(description))
+ fmt.Fprintf(r, `<a href="%s"><img src="%s" alt="%s" /></a>`, link, imageSrc, imageSrc)
+ }
case "video":
- videoSrc := getMediaURL(link)
- fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, videoSrc, description, description)
+ if l.Description == nil {
+ imageSrc := getMediaURL(link)
+ fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link)
+ } else {
+ description := strings.TrimPrefix(org.String(l.Description...), "file:")
+ videoSrc := getMediaURL([]byte(description))
+ fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc)
+ }
default:
+ description := string(link)
+ if l.Description != nil {
+ description = r.WriteNodesAsString(l.Description...)
+ }
fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
}
}