From 487ff53ffa93ecf65055198a4f31c3390e6a1c15 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 25 Jan 2024 21:37:19 +0000 Subject: [PATCH 1/2] Strip / from relative links. --- modules/markup/markdown/goldmark.go | 10 +++++---- modules/markup/markdown/markdown_test.go | 26 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index 1db3cbad7e1b0..3dc5530e008c8 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -85,9 +85,11 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa // 2. If they're not wrapped with a link they need a link wrapper // Check if the destination is a real link - link := v.Destination - if len(link) > 0 && !markup.IsLink(link) { - v.Destination = []byte(giteautil.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), string(link))) + if len(v.Destination) > 0 && !markup.IsLink(v.Destination) { + v.Destination = []byte(giteautil.URLJoin( + ctx.Links.ResolveMediaLink(ctx.IsWiki), + strings.TrimLeft(string(v.Destination), "/"), + )) } parent := n.Parent() @@ -103,7 +105,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa // Duplicate the current image node image := ast.NewImage(ast.NewLink()) - image.Destination = link + image.Destination = v.Destination image.Title = v.Title for _, attr := range v.Attributes() { image.SetAttribute(attr.Name, attr.Value) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 1edfb3e664463..3079a5ef2b822 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -580,6 +580,8 @@ https://example.com/file.bin [[local link|file.bin]] [[remote link|https://example.com]] ![local image](image.jpg) +![local image](attachments/cc42dfde) +![local image](/attachments/cc42dfde) ![remote image](https://example.com/image.jpg) [[local image|image.jpg]] [[remote link|https://example.com/image.jpg]] @@ -609,6 +611,8 @@ mail@domain.com local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -634,6 +638,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -661,6 +667,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -688,6 +696,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -715,6 +725,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -742,6 +754,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -770,6 +784,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -798,6 +814,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -826,6 +844,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -854,6 +874,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -883,6 +905,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
@@ -912,6 +936,8 @@ space

local link
remote link
local image
+local image
+local image
remote image
local image
remote link
From 5cd74cbf6d77db0fe25b8e4ebeac2befd2123203 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 26 Jan 2024 23:25:58 +0100 Subject: [PATCH 2/2] Update markdown_test.go --- modules/markup/markdown/markdown_test.go | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 3079a5ef2b822..bdf4011fa2486 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -580,8 +580,8 @@ https://example.com/file.bin [[local link|file.bin]] [[remote link|https://example.com]] ![local image](image.jpg) -![local image](attachments/cc42dfde) -![local image](/attachments/cc42dfde) +![local image](path/file) +![local image](/path/file) ![remote image](https://example.com/image.jpg) [[local image|image.jpg]] [[remote link|https://example.com/image.jpg]] @@ -611,8 +611,8 @@ mail@domain.com local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -638,8 +638,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -667,8 +667,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -696,8 +696,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -725,8 +725,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -754,8 +754,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -784,8 +784,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -814,8 +814,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -844,8 +844,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -874,8 +874,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -905,8 +905,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link
@@ -936,8 +936,8 @@ space

local link
remote link
local image
-local image
-local image
+local image
+local image
remote image
local image
remote link