Skip to content

Commit 481e738

Browse files
authored
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 `<p><a href="https://example.com" title="pre <video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video> post">pre <video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video> post</a></p>` 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`.
1 parent 6035733 commit 481e738

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

modules/markup/orgmode/orgmode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
158158
case "image":
159159
if l.Description == nil {
160160
imageSrc := getMediaURL(link)
161-
fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link)
161+
fmt.Fprintf(r, `<img src="%s" alt="%s" />`, imageSrc, link)
162162
} else {
163163
description := strings.TrimPrefix(org.String(l.Description...), "file:")
164164
imageSrc := getMediaURL([]byte(description))
@@ -167,18 +167,18 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
167167
case "video":
168168
if l.Description == nil {
169169
imageSrc := getMediaURL(link)
170-
fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link)
170+
fmt.Fprintf(r, `<video src="%s">%s</video>`, imageSrc, link)
171171
} else {
172172
description := strings.TrimPrefix(org.String(l.Description...), "file:")
173173
videoSrc := getMediaURL([]byte(description))
174-
fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc)
174+
fmt.Fprintf(r, `<a href="%s"><video src="%s">%s</video></a>`, link, videoSrc, videoSrc)
175175
}
176176
default:
177177
description := string(link)
178178
if l.Description != nil {
179179
description = r.WriteNodesAsString(l.Description...)
180180
}
181-
fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
181+
fmt.Fprintf(r, `<a href="%s">%s</a>`, link, description)
182182
}
183183
}
184184

modules/markup/orgmode/orgmode_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ func TestRender_StandardLinks(t *testing.T) {
3434
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3535
}
3636

37-
googleRendered := "<p><a href=\"https://google.com/\" title=\"https://google.com/\">https://google.com/</a></p>"
38-
test("[[https://google.com/]]", googleRendered)
37+
test("[[https://google.com/]]",
38+
`<p><a href="https://google.com/">https://google.com/</a></p>`)
3939

4040
lnk := util.URLJoin(AppSubURL, "WikiPage")
4141
test("[[WikiPage][WikiPage]]",
42-
"<p><a href=\""+lnk+"\" title=\"WikiPage\">WikiPage</a></p>")
42+
`<p><a href="`+lnk+`">WikiPage</a></p>`)
4343
}
4444

4545
func TestRender_Media(t *testing.T) {
@@ -59,19 +59,23 @@ func TestRender_Media(t *testing.T) {
5959
result := util.URLJoin(AppSubURL, url)
6060

6161
test("[[file:"+url+"]]",
62-
"<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>")
62+
`<p><img src="`+result+`" alt="`+result+`" /></p>`)
6363

6464
// With description.
6565
test("[[https://example.com][https://example.com/example.svg]]",
6666
`<p><a href="https://example.com"><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></a></p>`)
67+
test("[[https://example.com][pre https://example.com/example.svg post]]",
68+
`<p><a href="https://example.com">pre <img src="https://example.com/example.svg" alt="https://example.com/example.svg" /> post</a></p>`)
6769
test("[[https://example.com][https://example.com/example.mp4]]",
68-
`<p><a href="https://example.com"><video src="https://example.com/example.mp4" title="https://example.com/example.mp4"></video></a></p>`)
70+
`<p><a href="https://example.com"><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></a></p>`)
71+
test("[[https://example.com][pre https://example.com/example.mp4 post]]",
72+
`<p><a href="https://example.com">pre <video src="https://example.com/example.mp4">https://example.com/example.mp4</video> post</a></p>`)
6973

7074
// Without description.
7175
test("[[https://example.com/example.svg]]",
72-
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" title="https://example.com/example.svg" /></p>`)
76+
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></p>`)
7377
test("[[https://example.com/example.mp4]]",
74-
`<p><video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
78+
`<p><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
7579
}
7680

7781
func TestRender_Source(t *testing.T) {

0 commit comments

Comments
 (0)