2022-10-22 11:15:52 -06:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-10-22 11:15:52 -06:00
|
|
|
|
|
|
|
package markup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/user"
|
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2024-02-27 00:12:22 -07:00
|
|
|
gitea_context "code.gitea.io/gitea/services/context"
|
2022-10-22 11:15:52 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func ProcessorHelper() *markup.ProcessorHelper {
|
|
|
|
return &markup.ProcessorHelper{
|
2023-05-20 15:02:52 -06:00
|
|
|
ElementDir: "auto", // set dir="auto" for necessary (eg: <p>, <h?>, etc) tags
|
2024-04-02 12:20:16 -06:00
|
|
|
|
|
|
|
RenderRepoFileCodePreview: renderRepoFileCodePreview,
|
2022-10-22 11:15:52 -06:00
|
|
|
IsUsernameMentionable: func(ctx context.Context, username string) bool {
|
2022-10-23 03:13:52 -06:00
|
|
|
mentionedUser, err := user.GetUserByName(ctx, username)
|
2022-10-22 11:15:52 -06:00
|
|
|
if err != nil {
|
2022-10-23 03:13:52 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
giteaCtx, ok := ctx.(*gitea_context.Context)
|
|
|
|
if !ok {
|
|
|
|
// when using general context, use user's visibility to check
|
|
|
|
return mentionedUser.Visibility.IsPublic()
|
2022-10-22 11:15:52 -06:00
|
|
|
}
|
2022-10-23 03:13:52 -06:00
|
|
|
|
|
|
|
// when using gitea context (web context), use user's visibility and user's permission to check
|
|
|
|
return user.IsUserVisibleToViewer(giteaCtx, mentionedUser, giteaCtx.Doer)
|
2022-10-22 11:15:52 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|