From 21783a5752f518e579d8fe48b33504a16674ee17 Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Tue, 18 Jun 2024 11:09:20 +0800
Subject: Fix rendered wiki page link (#31398)
Fix #31395
---
modules/markup/markdown/markdown_test.go | 10 +++++-----
modules/markup/markdown/transform_link.go | 29 ++---------------------------
2 files changed, 7 insertions(+), 32 deletions(-)
(limited to 'modules/markup/markdown')
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 8c41ec12e3..9a8c39df0a 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -635,7 +635,7 @@ mail@domain.com
https://example.com/file.bin
local link
remote link
-local link
+local link
remote link


@@ -691,7 +691,7 @@ space
https://example.com/file.bin
local link
remote link
-local link
+local link
remote link


@@ -749,7 +749,7 @@ space
https://example.com/file.bin
local link
remote link
-local link
+local link
remote link


@@ -866,7 +866,7 @@ space
Expected: `space @mention-user
/just/a/path.bin
https://example.com/file.bin
-local link
+local link
remote link
local link
remote link
@@ -984,7 +984,7 @@ space
for i, c := range cases {
result, err := markdown.RenderString(&markup.RenderContext{Ctx: context.Background(), Links: c.Links, IsWiki: c.IsWiki}, input)
assert.NoError(t, err, "Unexpected error in testcase: %v", i)
- assert.Equal(t, template.HTML(c.Expected), result, "Unexpected result in testcase %v", i)
+ assert.Equal(t, c.Expected, string(result), "Unexpected result in testcase %v", i)
}
}
diff --git a/modules/markup/markdown/transform_link.go b/modules/markup/markdown/transform_link.go
index 527a5dfc44..38fbf693ab 100644
--- a/modules/markup/markdown/transform_link.go
+++ b/modules/markup/markdown/transform_link.go
@@ -4,38 +4,13 @@
package markdown
import (
- "path/filepath"
-
"code.gitea.io/gitea/modules/markup"
- giteautil "code.gitea.io/gitea/modules/util"
"github.com/yuin/goldmark/ast"
)
func (g *ASTTransformer) transformLink(ctx *markup.RenderContext, v *ast.Link) {
- // Links need their href to munged to be a real value
- link := v.Destination
- isAnchorFragment := len(link) > 0 && link[0] == '#'
- if !isAnchorFragment && !markup.IsFullURLBytes(link) {
- base := ctx.Links.Base
- if ctx.IsWiki {
- if filepath.Ext(string(link)) == "" {
- // This link doesn't have a file extension - assume a regular wiki link
- base = ctx.Links.WikiLink()
- } else if markup.Type(string(link)) != "" {
- // If it's a file type we can render, use a regular wiki link
- base = ctx.Links.WikiLink()
- } else {
- // Otherwise, use a raw link instead
- base = ctx.Links.WikiRawLink()
- }
- } else if ctx.Links.HasBranchInfo() {
- base = ctx.Links.SrcLink()
- }
- link = []byte(giteautil.URLJoin(base, string(link)))
- }
- if isAnchorFragment {
- link = []byte("#user-content-" + string(link)[1:])
+ if link, resolved := markup.ResolveLink(ctx, string(v.Destination), "#user-content-"); resolved {
+ v.Destination = []byte(link)
}
- v.Destination = link
}
--
cgit v1.2.3
e/xmlgraphics-fopwww-data |
blob: 3c099dacb2507eb1a7517efc1a043da235c1869d (
plain)