aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorPranav Nachnekar <pranavnachanekar@pm.me>2020-10-01 20:52:34 +0530
committerGitHub <noreply@github.com>2020-10-01 11:22:34 -0400
commit1827f892de52ececac2ca5dc397a11bfbcc0da43 (patch)
tree9c06a8cb03e8152d49c14631c79f752df1dddcbb /modules
parent1d2553abbf2067761061c87258c612956fd10d34 (diff)
downloadgitea-1827f892de52ececac2ca5dc397a11bfbcc0da43.tar.gz
gitea-1827f892de52ececac2ca5dc397a11bfbcc0da43.zip
fix: media links in org files not liked to media files (#12997)
* fix: media links in org files not liked to media files * fix: write directly to io.Writer r as suggested by code review Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/markup/orgmode/orgmode.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go
index 86222cc88e..ddd445aba2 100644
--- a/modules/markup/orgmode/orgmode.go
+++ b/modules/markup/orgmode/orgmode.go
@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"html"
+ "strings"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
@@ -94,10 +95,23 @@ func (r *Renderer) WriteRegularLink(l org.RegularLink) {
}
switch l.Kind() {
case "image":
- r.WriteString(fmt.Sprintf(`<img src="%s" alt="%s" title="%s" />`, link, description, description))
+ imageSrc := getMediaURL(link)
+ fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, description, description)
case "video":
- r.WriteString(fmt.Sprintf(`<video src="%s" title="%s">%s</video>`, link, description, description))
+ videoSrc := getMediaURL(link)
+ fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, videoSrc, description, description)
default:
- r.WriteString(fmt.Sprintf(`<a href="%s" title="%s">%s</a>`, link, description, description))
+ fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
}
}
+
+func getMediaURL(l []byte) string {
+ srcURL := string(l)
+
+ // Check if link is valid
+ if len(srcURL) > 0 && !markup.IsLink(l) {
+ srcURL = strings.Replace(srcURL, "/src/", "/media/", 1)
+ }
+
+ return srcURL
+}