aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-11-10 02:45:13 +0100
committerGitHub <noreply@github.com>2023-11-10 01:45:13 +0000
commit481e738e7f3ee22a5a8280d155a1b7d1ff09bc7f (patch)
treefc6e50cec7f5fd13baad84097b3d2027fb24c99a /modules/markup
parent603573366a203efae06f818a0b220be964cdac21 (diff)
downloadgitea-481e738e7f3ee22a5a8280d155a1b7d1ff09bc7f.tar.gz
gitea-481e738e7f3ee22a5a8280d155a1b7d1ff09bc7f.zip
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`.
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/orgmode/orgmode.go8
-rw-r--r--modules/markup/orgmode/orgmode_test.go18
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, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link)
+ fmt.Fprintf(r, `<img src="%s" alt="%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, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link)
+ fmt.Fprintf(r, `<video src="%s">%s</video>`, imageSrc, link)
} else {
description := strings.TrimPrefix(org.String(l.Description...), "file:")
videoSrc := getMediaURL([]byte(description))
- fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc)
+ fmt.Fprintf(r, `<a href="%s"><video src="%s">%s</video></a>`, link, videoSrc, videoSrc)
}
default:
description := string(link)
if l.Description != nil {
description = r.WriteNodesAsString(l.Description...)
}
- fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
+ fmt.Fprintf(r, `<a href="%s">%s</a>`, 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 := "<p><a href=\"https://google.com/\" title=\"https://google.com/\">https://google.com/</a></p>"
- test("[[https://google.com/]]", googleRendered)
+ test("[[https://google.com/]]",
+ `<p><a href="https://google.com/">https://google.com/</a></p>`)
lnk := util.URLJoin(AppSubURL, "WikiPage")
test("[[WikiPage][WikiPage]]",
- "<p><a href=\""+lnk+"\" title=\"WikiPage\">WikiPage</a></p>")
+ `<p><a href="`+lnk+`">WikiPage</a></p>`)
}
func TestRender_Media(t *testing.T) {
@@ -59,19 +59,23 @@ func TestRender_Media(t *testing.T) {
result := util.URLJoin(AppSubURL, url)
test("[[file:"+url+"]]",
- "<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>")
+ `<p><img src="`+result+`" alt="`+result+`" /></p>`)
// With description.
test("[[https://example.com][https://example.com/example.svg]]",
`<p><a href="https://example.com"><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></a></p>`)
+ test("[[https://example.com][pre https://example.com/example.svg post]]",
+ `<p><a href="https://example.com">pre <img src="https://example.com/example.svg" alt="https://example.com/example.svg" /> post</a></p>`)
test("[[https://example.com][https://example.com/example.mp4]]",
- `<p><a href="https://example.com"><video src="https://example.com/example.mp4" title="https://example.com/example.mp4"></video></a></p>`)
+ `<p><a href="https://example.com"><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></a></p>`)
+ test("[[https://example.com][pre https://example.com/example.mp4 post]]",
+ `<p><a href="https://example.com">pre <video src="https://example.com/example.mp4">https://example.com/example.mp4</video> post</a></p>`)
// Without description.
test("[[https://example.com/example.svg]]",
- `<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" title="https://example.com/example.svg" /></p>`)
+ `<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></p>`)
test("[[https://example.com/example.mp4]]",
- `<p><video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
+ `<p><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
}
func TestRender_Source(t *testing.T) {