diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 2002cbc41b..4ad4f175a2 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -7,6 +7,7 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "net/http" + "regexp" ) const ( @@ -18,7 +19,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], ctx.Data["TransformedTrustProps"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences") if err != nil { ctx.ServerError("Render", err) @@ -48,7 +49,12 @@ func ToggleCompetences(ctx *context.Context) { return } - repo.Competences = toggledContent + repo.Competences, err = trimSearchLinks(toggledContent) + if err != nil { + ctx.ServerError("trimSearchLinks", err) + return + } + err = repo_model.UpdateRepositoryCols(repo, "competences") if err != nil { ctx.ServerError("ToggleCompetences", err) @@ -64,3 +70,12 @@ func ToggleCompetences(ctx *context.Context) { responseBody, ) } + +func trimSearchLinks(content string) (string, error) { + regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) + if err != nil { + return "", err + } + trimmedSearchLink := regExp.ReplaceAllString(content, "") + return trimmedSearchLink, nil +} diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index bcf7f76595..a5ca592219 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -19,7 +19,7 @@ func Resources(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") + ctx.Data["RenderedResources"], ctx.Data["TransformedTrustProps"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) @@ -29,7 +29,7 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { +func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, string, error) { trustProps := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp @@ -37,7 +37,7 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} regExp, err = regexp.Compile(`- \[ \] (.+)`) if err != nil { - return "", err + return "", "", err } trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) @@ -66,5 +66,5 @@ func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{} var renderedTrustPropsWithSafeURLs string renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, " {{$.RenderedCompetences | Str2html}} -
{{.Repository.Competences}}
+
{{$.TransformedTrustProps}}