From 481e738e7f3ee22a5a8280d155a1b7d1ff09bc7f Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 10 Nov 2023 02:45:13 +0100 Subject: [PATCH] Remove `title` from elements on Org mode (#27968) The Org mode rendering has some problems: 1. `[[https://example.com][pre https://example.com/example.mp4 post]]` renders as `

https://example.com/example.mp4 post">pre post

` As you can see, the `title` attribute contains the inner html in unescaped form. I removed the `title` attribute because it is of little value. 3. The `title` attribute on `img` and `video` is of little value. 4. The inner elements of `video` are different depending on the `if`. --- modules/markup/orgmode/orgmode.go | 8 ++++---- modules/markup/orgmode/orgmode_test.go | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 9b6175649f..c1e0144199 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -158,7 +158,7 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) { case "image": if l.Description == nil { imageSrc := getMediaURL(link) - fmt.Fprintf(r, `%s`, imageSrc, link, link) + fmt.Fprintf(r, `%s`, imageSrc, link) } else { description := strings.TrimPrefix(org.String(l.Description...), "file:") imageSrc := getMediaURL([]byte(description)) @@ -167,18 +167,18 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) { case "video": if l.Description == nil { imageSrc := getMediaURL(link) - fmt.Fprintf(r, ``, imageSrc, link, link) + fmt.Fprintf(r, ``, imageSrc, link) } else { description := strings.TrimPrefix(org.String(l.Description...), "file:") videoSrc := getMediaURL([]byte(description)) - fmt.Fprintf(r, ``, link, videoSrc, videoSrc) + 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) + fmt.Fprintf(r, `%s`, link, description) } } diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go index 8f454e9955..88ae14ebcf 100644 --- a/modules/markup/orgmode/orgmode_test.go +++ b/modules/markup/orgmode/orgmode_test.go @@ -34,12 +34,12 @@ func TestRender_StandardLinks(t *testing.T) { assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) } - googleRendered := "

https://google.com/

" - test("[[https://google.com/]]", googleRendered) + test("[[https://google.com/]]", + `

https://google.com/

`) lnk := util.URLJoin(AppSubURL, "WikiPage") test("[[WikiPage][WikiPage]]", - "

WikiPage

") + `

WikiPage

`) } func TestRender_Media(t *testing.T) { @@ -59,19 +59,23 @@ func TestRender_Media(t *testing.T) { result := util.URLJoin(AppSubURL, url) test("[[file:"+url+"]]", - "

\""+result+"\"

") + `

`+result+`

`) // With description. test("[[https://example.com][https://example.com/example.svg]]", `

https://example.com/example.svg

`) + test("[[https://example.com][pre https://example.com/example.svg post]]", + `

pre https://example.com/example.svg post

`) test("[[https://example.com][https://example.com/example.mp4]]", - `

`) + `

`) + test("[[https://example.com][pre https://example.com/example.mp4 post]]", + `

pre post

`) // Without description. test("[[https://example.com/example.svg]]", - `

https://example.com/example.svg

`) + `

https://example.com/example.svg

`) test("[[https://example.com/example.mp4]]", - `

`) + `

`) } func TestRender_Source(t *testing.T) {