code.gitea.io/gitea@v1.22.3/services/markup/processorhelper.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package markup 5 6 import ( 7 "context" 8 9 "code.gitea.io/gitea/models/user" 10 "code.gitea.io/gitea/modules/markup" 11 gitea_context "code.gitea.io/gitea/services/context" 12 ) 13 14 func ProcessorHelper() *markup.ProcessorHelper { 15 return &markup.ProcessorHelper{ 16 ElementDir: "auto", // set dir="auto" for necessary (eg: <p>, <h?>, etc) tags 17 18 RenderRepoFileCodePreview: renderRepoFileCodePreview, 19 IsUsernameMentionable: func(ctx context.Context, username string) bool { 20 mentionedUser, err := user.GetUserByName(ctx, username) 21 if err != nil { 22 return false 23 } 24 25 giteaCtx, ok := ctx.(*gitea_context.Context) 26 if !ok { 27 // when using general context, use user's visibility to check 28 return mentionedUser.Visibility.IsPublic() 29 } 30 31 // when using gitea context (web context), use user's visibility and user's permission to check 32 return user.IsUserVisibleToViewer(giteaCtx, mentionedUser, giteaCtx.Doer) 33 }, 34 } 35 }