summaryrefslogtreecommitdiffstats
path: root/modules/markup/orgmode/orgmode_test.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2024-01-16 03:13:29 +0100
committerGitHub <noreply@github.com>2024-01-16 02:13:29 +0000
commit022552d5b6adc792d3cd16df7de6e52cb7b41a72 (patch)
tree4c709003d9d529475f563ff3997b7be874448052 /modules/markup/orgmode/orgmode_test.go
parent376fa0d8c49ca8a290ebb328281a56af346f5785 (diff)
downloadgitea-022552d5b6adc792d3cd16df7de6e52cb7b41a72.tar.gz
gitea-022552d5b6adc792d3cd16df7de6e52cb7b41a72.zip
Rework markup link rendering (#26745) (#28803)
Backport #26745 Fixes #26548 This PR refactors the rendering of markup links. The old code uses `strings.Replace` to change some urls while the new code uses more context to decide which link should be generated. The added tests should ensure the same output for the old and new behaviour (besides the bug). We may need to refactor the rendering a bit more to make it clear how the different helper methods render the input string. There are lots of options (resolve links / images / mentions / git hashes / emojis / ...) but you don't really know what helper uses which options. For example, we currently support images in the user description which should not be allowed I think: <details> <summary>Profile</summary> https://try.gitea.io/KN4CK3R ![grafik](https://github.com/go-gitea/gitea/assets/1666336/109ae422-496d-4200-b52e-b3a528f553e5) </details>
Diffstat (limited to 'modules/markup/orgmode/orgmode_test.go')
-rw-r--r--modules/markup/orgmode/orgmode_test.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/modules/markup/orgmode/orgmode_test.go b/modules/markup/orgmode/orgmode_test.go
index 8f454e9955..cb9b24f6d0 100644
--- a/modules/markup/orgmode/orgmode_test.go
+++ b/modules/markup/orgmode/orgmode_test.go
@@ -27,8 +27,10 @@ func TestRender_StandardLinks(t *testing.T) {
test := func(input, expected string) {
buffer, err := RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: setting.AppSubURL,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: setting.AppSubURL,
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -48,8 +50,10 @@ func TestRender_Media(t *testing.T) {
test := func(input, expected string) {
buffer, err := RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: setting.AppSubURL,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: setting.AppSubURL,
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -59,19 +63,19 @@ 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][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>`)
// 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) {
@@ -80,8 +84,7 @@ func TestRender_Source(t *testing.T) {
test := func(input, expected string) {
buffer, err := RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: setting.AppSubURL,
+ Ctx: git.DefaultContext,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))