File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -142,10 +142,18 @@ func (r *Writer) resolveLink(kind, link string) string {
142
142
// so we need to try to guess the link kind again here
143
143
kind = org.RegularLink {URL : link }.Kind ()
144
144
}
145
+
145
146
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
+
146
153
if kind == "image" || kind == "video" {
147
154
base = r .Ctx .Links .ResolveMediaLink (r .Ctx .IsWiki )
148
155
}
156
+
149
157
link = util .URLJoin (base , link )
150
158
}
151
159
return link
Original file line number Diff line number Diff line change @@ -39,6 +39,31 @@ func TestRender_StandardLinks(t *testing.T) {
39
39
`<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc</a></p>` )
40
40
}
41
41
42
+ func TestRender_InternalLinks (t * testing.T ) {
43
+ setting .AppURL = AppURL
44
+
45
+ test := func (input , expected string ) {
46
+ buffer , err := RenderString (& markup.RenderContext {
47
+ Ctx : git .DefaultContext ,
48
+ Links : markup.Links {
49
+ Base : "/relative-path" ,
50
+ BranchPath : "branch/main" ,
51
+ },
52
+ }, input )
53
+ assert .NoError (t , err )
54
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
55
+ }
56
+
57
+ test ("[[file:test.org][Test]]" ,
58
+ `<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>` )
59
+ test ("[[./test.org][Test]]" ,
60
+ `<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>` )
61
+ test ("[[test.org][Test]]" ,
62
+ `<p><a href="/relative-path/src/branch/main/test.org">Test</a></p>` )
63
+ test ("[[path/to/test.org][Test]]" ,
64
+ `<p><a href="/relative-path/src/branch/main/path/to/test.org">Test</a></p>` )
65
+ }
66
+
42
67
func TestRender_Media (t * testing.T ) {
43
68
setting .AppURL = AppURL
44
69
You can’t perform that action at this time.
0 commit comments