Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package markup
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/references"
|
|
"code.gitcaddy.com/server/v3/modules/util"
|
|
|
|
"golang.org/x/net/html"
|
|
)
|
|
|
|
func mentionProcessor(ctx *RenderContext, node *html.Node) {
|
|
start := 0
|
|
nodeStop := node.NextSibling
|
|
for node != nodeStop {
|
|
found, loc := references.FindFirstMentionBytes(util.UnsafeStringToBytes(node.Data[start:]))
|
|
if !found {
|
|
node = node.NextSibling
|
|
start = 0
|
|
continue
|
|
}
|
|
loc.Start += start
|
|
loc.End += start
|
|
mention := node.Data[loc.Start:loc.End]
|
|
teams, ok := ctx.RenderOptions.Metas["teams"]
|
|
// FIXME: util.URLJoin may not be necessary here:
|
|
// - setting.AppURL is defined to have a terminal '/' so unless mention[1:]
|
|
// is an AppSubURL link we can probably fallback to concatenation.
|
|
// team mention should follow @orgName/teamName style
|
|
if ok && strings.Contains(mention, "/") {
|
|
mentionOrgAndTeam := strings.Split(mention, "/")
|
|
if mentionOrgAndTeam[0][1:] == ctx.RenderOptions.Metas["org"] && strings.Contains(teams, ","+strings.ToLower(mentionOrgAndTeam[1])+",") {
|
|
link := "/:root/" + util.URLJoin("org", ctx.RenderOptions.Metas["org"], "teams", mentionOrgAndTeam[1])
|
|
replaceContent(node, loc.Start, loc.End, createLink(ctx, link, mention, "" /*mention*/))
|
|
node = node.NextSibling.NextSibling
|
|
start = 0
|
|
continue
|
|
}
|
|
start = loc.End
|
|
continue
|
|
}
|
|
mentionedUsername := mention[1:]
|
|
|
|
if DefaultRenderHelperFuncs != nil && DefaultRenderHelperFuncs.IsUsernameMentionable(ctx, mentionedUsername) {
|
|
link := "/:root/" + mentionedUsername
|
|
replaceContent(node, loc.Start, loc.End, createLink(ctx, link, mention, "" /*mention*/))
|
|
node = node.NextSibling.NextSibling
|
|
start = 0
|
|
} else {
|
|
start = loc.End
|
|
}
|
|
}
|
|
}
|