|
8 | 8 | "bytes"
|
9 | 9 | "fmt"
|
10 | 10 | "html"
|
| 11 | + "strings" |
11 | 12 |
|
12 | 13 | "code.gitea.io/gitea/modules/log"
|
13 | 14 | "code.gitea.io/gitea/modules/markup"
|
@@ -94,10 +95,23 @@ func (r *Renderer) WriteRegularLink(l org.RegularLink) {
|
94 | 95 | }
|
95 | 96 | switch l.Kind() {
|
96 | 97 | case "image":
|
97 |
| - r.WriteString(fmt.Sprintf(`<img src="%s" alt="%s" title="%s" />`, link, description, description)) |
| 98 | + imageSrc := getMediaURL(link) |
| 99 | + fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, description, description) |
98 | 100 | case "video":
|
99 |
| - r.WriteString(fmt.Sprintf(`<video src="%s" title="%s">%s</video>`, link, description, description)) |
| 101 | + videoSrc := getMediaURL(link) |
| 102 | + fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, videoSrc, description, description) |
100 | 103 | default:
|
101 |
| - r.WriteString(fmt.Sprintf(`<a href="%s" title="%s">%s</a>`, link, description, description)) |
| 104 | + fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description) |
102 | 105 | }
|
103 | 106 | }
|
| 107 | + |
| 108 | +func getMediaURL(l []byte) string { |
| 109 | + srcURL := string(l) |
| 110 | + |
| 111 | + // Check if link is valid |
| 112 | + if len(srcURL) > 0 && !markup.IsLink(l) { |
| 113 | + srcURL = strings.Replace(srcURL, "/src/", "/media/", 1) |
| 114 | + } |
| 115 | + |
| 116 | + return srcURL |
| 117 | +} |
0 commit comments