mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 14:25:02 +02:00
fix(markup): resolve and proxy srcset links of <source> elements (#39708)
1. use correct links for srcset attribute of picture source 2. wrap the picture element with a link correctly --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
bd28f254fa
commit
a1cc651267
9 files changed
+247
-14
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/markup/markdown"
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
_ "gitea.dev/modules/markup/orgmode"
|
||||
|
||||
@@ -80,6 +81,23 @@ func TestRepoFile(t *testing.T) {
|
||||
<video src="/user2/repo1/media/commit/1234/my%20dir/LINK">
|
||||
</video>`, rendered)
|
||||
})
|
||||
|
||||
t.Run("PictureSource", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefSubURL: "branch/main"}).
|
||||
WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := testRenderString(rctx, `<picture><source media="(prefers-color-scheme: dark)" srcset="dark.svg"><img src="light.svg"></picture>`)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.NormalizeHTMLSpaces(`
|
||||
<p>
|
||||
<a href="/user2/repo1/src/branch/main/light.svg" target="_blank" rel="nofollow noopener">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="/user2/repo1/media/branch/main/dark.svg"/>
|
||||
<img src="/user2/repo1/media/branch/main/light.svg"/>
|
||||
</picture>
|
||||
</a>
|
||||
</p>
|
||||
`), test.NormalizeHTMLSpaces(rendered))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRepoFileOrgMode(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user