Skip to content

Commit 94208c1

Browse files
committed
Merge branch 'locale-cleanup' of ssh://github.com/denyskon/gitea into locale-cleanup
2 parents e04497d + 732b74e commit 94208c1

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

modules/markup/orgmode/orgmode.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,18 @@ func (r *Writer) resolveLink(kind, link string) string {
142142
// so we need to try to guess the link kind again here
143143
kind = org.RegularLink{URL: link}.Kind()
144144
}
145+
145146
base := r.Ctx.Links.Base
147+
if r.Ctx.IsWiki {
148+
base = r.Ctx.Links.WikiLink()
149+
} else if r.Ctx.Links.HasBranchInfo() {
150+
base = r.Ctx.Links.SrcLink()
151+
}
152+
146153
if kind == "image" || kind == "video" {
147154
base = r.Ctx.Links.ResolveMediaLink(r.Ctx.IsWiki)
148155
}
156+
149157
link = util.URLJoin(base, link)
150158
}
151159
return link

modules/markup/orgmode/orgmode_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,50 @@ const AppURL = "http://localhost:3000/"
1919
func TestRender_StandardLinks(t *testing.T) {
2020
setting.AppURL = AppURL
2121

22-
test := func(input, expected string) {
22+
test := func(input, expected string, isWiki bool) {
2323
buffer, err := RenderString(&markup.RenderContext{
2424
Ctx: git.DefaultContext,
2525
Links: markup.Links{
2626
Base: "/relative-path",
2727
BranchPath: "branch/main",
2828
},
29+
IsWiki: isWiki,
2930
}, input)
3031
assert.NoError(t, err)
3132
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3233
}
3334

3435
test("[[https://google.com/]]",
35-
`<p><a href="https://google.com/">https://google.com/</a></p>`)
36+
`<p><a href="https://google.com/">https://google.com/</a></p>`, false)
3637
test("[[WikiPage][The WikiPage Desc]]",
37-
`<p><a href="/relative-path/WikiPage">The WikiPage Desc</a></p>`)
38+
`<p><a href="/relative-path/wiki/WikiPage">The WikiPage Desc</a></p>`, true)
3839
test("[[ImageLink.svg][The Image Desc]]",
39-
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`)
40+
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>`, false)
41+
}
42+
43+
func TestRender_InternalLinks(t *testing.T) {
44+
setting.AppURL = AppURL
45+
46+
test := func(input, expected string) {
47+
buffer, err := RenderString(&markup.RenderContext{
48+
Ctx: git.DefaultContext,
49+
Links: markup.Links{
50+
Base: "/relative-path",
51+
BranchPath: "branch/main",
52+
},
53+
}, input)
54+
assert.NoError(t, err)
55+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
56+
}
57+
58+
test("[[file:test.org][Test]]",
59+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
60+
test("[[./test.org][Test]]",
61+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
62+
test("[[test.org][Test]]",
63+
`<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>`)
64+
test("[[path/to/test.org][Test]]",
65+
`<p><a href="/relative-path/src/branch/main/path/to/test.org">Test</a></p>`)
4066
}
4167

4268
func TestRender_Media(t *testing.T) {

0 commit comments

Comments
 (0)