diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 5a8485e571..7a4482d120 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -153,18 +153,30 @@ 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...) - } switch l.Kind() { case "image": - imageSrc := getMediaURL(link) - fmt.Fprintf(r, ``, imageSrc, description, description) + if l.Description == nil { + imageSrc := getMediaURL(link) + fmt.Fprintf(r, ``, imageSrc, link, link) + } else { + description := strings.TrimPrefix(org.String(l.Description), "file:") + imageSrc := getMediaURL([]byte(description)) + fmt.Fprintf(r, ``, link, imageSrc, imageSrc) + } case "video": - videoSrc := getMediaURL(link) - fmt.Fprintf(r, ``, videoSrc, description, description) + if l.Description == nil { + imageSrc := getMediaURL(link) + fmt.Fprintf(r, ``, imageSrc, link, link) + } else { + description := strings.TrimPrefix(org.String(l.Description), "file:") + videoSrc := getMediaURL([]byte(description)) + fmt.Fprintf(r, ``, link, videoSrc, videoSrc) + } default: + description := string(link) + if l.Description != nil { + description = r.WriteNodesAsString(l.Description...) + } fmt.Fprintf(r, `%s`, link, description, description) } } diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go index d6467c36f7..8f454e9955 100644 --- a/modules/markup/orgmode/orgmode_test.go +++ b/modules/markup/orgmode/orgmode_test.go @@ -42,7 +42,7 @@ func TestRender_StandardLinks(t *testing.T) { "
") } -func TestRender_Images(t *testing.T) { +func TestRender_Media(t *testing.T) { setting.AppURL = AppURL setting.AppSubURL = AppSubURL @@ -60,6 +60,18 @@ func TestRender_Images(t *testing.T) { test("[[file:"+url+"]]", "") + + // With description. + test("[[https://example.com][https://example.com/example.svg]]", + ``) + test("[[https://example.com][https://example.com/example.mp4]]", + ``) + + // Without description. + test("[[https://example.com/example.svg]]", + ``) + test("[[https://example.com/example.mp4]]", + ``) } func TestRender_Source(t *testing.T) {