From 27c5c54333e2c490db322824384391094d9e3de9 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 31 Jul 2023 13:14:13 +0200 Subject: [PATCH] don't post-proccess issue index in documents - Currently the post processing will transform all issue indexes (such as `#6`) into an clickable link. - This makes sense in an situation like issues or PRs, where referencing to other issues is quite common and only referencing to their issue indexing is an handy and efficient way to do it. - Currently this is also run for documents (which is the user profile and viewing rendered files), but in those situations it's less common to reference issues by their index and instead could mean something else. - This patch disables this post processing for issue index for documents. Which matches Github's behavior. - Added unit tests. - Resolves https://codeberg.org/Codeberg/Community/issues/1120 --- modules/markup/html.go | 2 +- modules/markup/html_internal_test.go | 24 +++++++++++++++++++ modules/markup/html_test.go | 36 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index da16bcd3cb3fe..e53ccc6a794a4 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -852,7 +852,7 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) { } func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) { - if ctx.Metas == nil { + if ctx.Metas == nil || ctx.Metas["mode"] == "document" { return } var ( diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 00ffe45c285b3..7b7f6df70106b 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -262,6 +262,30 @@ func TestRender_IssueIndexPattern5(t *testing.T) { }) } +func TestRender_IssueIndexPattern_Document(t *testing.T) { + setting.AppURL = TestAppURL + metas := map[string]string{ + "format": "https://someurl.com/{user}/{repo}/{index}", + "user": "someUser", + "repo": "someRepo", + "style": IssueNameStyleNumeric, + "mode": "document", + } + + testRenderIssueIndexPattern(t, "#1", "#1", &RenderContext{ + Ctx: git.DefaultContext, + Metas: metas, + }) + testRenderIssueIndexPattern(t, "#1312", "#1312", &RenderContext{ + Ctx: git.DefaultContext, + Metas: metas, + }) + testRenderIssueIndexPattern(t, "!1", "!1", &RenderContext{ + Ctx: git.DefaultContext, + Metas: metas, + }) +} + func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *RenderContext) { if ctx.URLPrefix == "" { ctx.URLPrefix = TestAppURL diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index a8d7ba7948ded..9156bc63312b6 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -529,6 +529,42 @@ func Test_ParseClusterFuzz(t *testing.T) { assert.NotContains(t, res.String(), ":gitea:`) + test( + "Some text with 😄 in the middle", + `Some text with 😄 in the middle`) + test("http://localhost:3000/person/repo/issues/4#issuecomment-1234", + `person/repo#4 (comment)`) +} + func TestIssue16020(t *testing.T) { setting.AppURL = TestAppURL