diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2023-01-30 02:50:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-30 09:50:01 +0800 |
commit | d0d257b243177d1ec9d9753adacd7dd9807408fa (patch) | |
tree | c0554cef106395fec8c08c9ee896a888aa32cd31 /modules/markup/html.go | |
parent | 3ff5a6a365ab32b6356292fa2266fa36bb08f293 (diff) | |
download | gitea-d0d257b243177d1ec9d9753adacd7dd9807408fa.tar.gz gitea-d0d257b243177d1ec9d9753adacd7dd9807408fa.zip |
Add support for commit cross references (#22645)
Fixes #22628
This PR adds cross references for commits by using the format
`owner/repo@commit` . References are rendered like
[go-gitea/lgtm@6fe88302](#dummy).
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/markup/html.go')
-rw-r--r-- | modules/markup/html.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go index 6b5a8e32d4..73ae768d76 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -164,6 +164,7 @@ var defaultProcessors = []processor{ linkProcessor, mentionProcessor, issueIndexPatternProcessor, + commitCrossReferencePatternProcessor, sha1CurrentPatternProcessor, emailAddressProcessor, emojiProcessor, @@ -190,6 +191,7 @@ var commitMessageProcessors = []processor{ linkProcessor, mentionProcessor, issueIndexPatternProcessor, + commitCrossReferencePatternProcessor, sha1CurrentPatternProcessor, emailAddressProcessor, emojiProcessor, @@ -221,6 +223,7 @@ var commitMessageSubjectProcessors = []processor{ linkProcessor, mentionProcessor, issueIndexPatternProcessor, + commitCrossReferencePatternProcessor, sha1CurrentPatternProcessor, emojiShortCodeProcessor, emojiProcessor, @@ -257,6 +260,7 @@ func RenderIssueTitle( ) (string, error) { return renderProcessString(ctx, []processor{ issueIndexPatternProcessor, + commitCrossReferencePatternProcessor, sha1CurrentPatternProcessor, emojiShortCodeProcessor, emojiProcessor, @@ -907,6 +911,23 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) { } } +func commitCrossReferencePatternProcessor(ctx *RenderContext, node *html.Node) { + next := node.NextSibling + + for node != nil && node != next { + found, ref := references.FindRenderizableCommitCrossReference(node.Data) + if !found { + return + } + + reftext := ref.Owner + "/" + ref.Name + "@" + base.ShortSha(ref.CommitSha) + link := createLink(util.URLJoin(setting.AppSubURL, ref.Owner, ref.Name, "commit", ref.CommitSha), reftext, "commit") + + replaceContent(node, ref.RefLocation.Start, ref.RefLocation.End, link) + node = node.NextSibling.NextSibling + } +} + // fullSha1PatternProcessor renders SHA containing URLs func fullSha1PatternProcessor(ctx *RenderContext, node *html.Node) { if ctx.Metas == nil { |