From 12c0487e01d3fd9fe289345c53e8a220be55e864 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 3 Jan 2024 07:01:12 +0100 Subject: [PATCH 1/6] Make cross-reference issue links work in markdown documents again (#28682) In #26365 issue references were disabled entirely for documents, intending to match GitHub behavior. However cross-references do appear to work in documents on GitHub. This is useful for example to write release notes in a markdown document and reference issues. While the simpler syntax may create links when not intended, hopefully the cross-reference syntax is unique enough to avoid it. --- modules/markup/html.go | 11 +++++++---- modules/markup/html_test.go | 7 ++++++- modules/references/references.go | 7 +++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 03168b6946814..05b1c3ef72a70 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -852,11 +852,14 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) { } func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) { - // FIXME: the use of "mode" is quite dirty and hacky, for example: what is a "document"? how should it be rendered? - // The "mode" approach should be refactored to some other more clear&reliable way. - if ctx.Metas == nil || (ctx.Metas["mode"] == "document" && !ctx.IsWiki) { + if ctx.Metas == nil { return } + + // FIXME: the use of "mode" is quite dirty and hacky, for example: what is a "document"? how should it be rendered? + // The "mode" approach should be refactored to some other more clear&reliable way. + crossLinkOnly := (ctx.Metas["mode"] == "document" && !ctx.IsWiki) + var ( found bool ref *references.RenderizableReference @@ -870,7 +873,7 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) { // Repos with external issue trackers might still need to reference local PRs // We need to concern with the first one that shows up in the text, whichever it is isNumericStyle := ctx.Metas["style"] == "" || ctx.Metas["style"] == IssueNameStyleNumeric - foundNumeric, refNumeric := references.FindRenderizableReferenceNumeric(node.Data, hasExtTrackFormat && !isNumericStyle) + foundNumeric, refNumeric := references.FindRenderizableReferenceNumeric(node.Data, hasExtTrackFormat && !isNumericStyle, crossLinkOnly) switch ctx.Metas["style"] { case "", IssueNameStyleNumeric: diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index d1f4e9e8a35b6..62fd0f5a85883 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -561,11 +561,16 @@ func TestPostProcess_RenderDocument(t *testing.T) { assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String())) } - // Issue index shouldn't be post processing in an document. + // Issue index shouldn't be post processing in a document. test( "#1", "#1") + // But cross-referenced issue index should work. + test( + "go-gitea/gitea#12345", + `go-gitea/gitea#12345`) + // Test that other post processing still works. test( ":gitea:", diff --git a/modules/references/references.go b/modules/references/references.go index 68662425cccf1..64a67d7da7c3d 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -331,8 +331,11 @@ func FindAllIssueReferences(content string) []IssueReference { } // FindRenderizableReferenceNumeric returns the first unvalidated reference found in a string. -func FindRenderizableReferenceNumeric(content string, prOnly bool) (bool, *RenderizableReference) { - match := issueNumericPattern.FindStringSubmatchIndex(content) +func FindRenderizableReferenceNumeric(content string, prOnly, crossLinkOnly bool) (bool, *RenderizableReference) { + var match []int + if !crossLinkOnly { + match = issueNumericPattern.FindStringSubmatchIndex(content) + } if match == nil { if match = crossReferenceIssueNumericPattern.FindStringSubmatchIndex(content); match == nil { return false, nil From 361839fb1c8bdfb8291bbcf9bd650b21a605bbd7 Mon Sep 17 00:00:00 2001 From: wackbyte Date: Wed, 3 Jan 2024 01:25:19 -0500 Subject: [PATCH 2/6] Fix tooltip of variable edit button (#28681) The `variables.edit` key does not exist. ![image](https://github.com/go-gitea/gitea/assets/29505620/462a1c6c-775c-466a-8398-37115b2af47a) --- templates/shared/variables/variable_list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/shared/variables/variable_list.tmpl b/templates/shared/variables/variable_list.tmpl index 790e270417cff..fc5cd966fcf4c 100644 --- a/templates/shared/variables/variable_list.tmpl +++ b/templates/shared/variables/variable_list.tmpl @@ -33,7 +33,7 @@ {{ctx.Locale.Tr "settings.added_on" (DateTime "short" .CreatedUnix) | Safe}}