gitea源码

html_email.go 850B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markup
  4. import (
  5. "strings"
  6. "golang.org/x/net/html"
  7. )
  8. // emailAddressProcessor replaces raw email addresses with a mailto: link.
  9. func emailAddressProcessor(ctx *RenderContext, node *html.Node) {
  10. next := node.NextSibling
  11. for node != nil && node != next {
  12. m := globalVars().emailRegex.FindStringSubmatchIndex(node.Data)
  13. if m == nil {
  14. return
  15. }
  16. var nextByte byte
  17. if len(node.Data) > m[3] {
  18. nextByte = node.Data[m[3]]
  19. }
  20. if strings.IndexByte(":/", nextByte) != -1 {
  21. // for cases: "git@gitea.com:owner/repo.git", "https://git@gitea.com/owner/repo.git"
  22. return
  23. }
  24. mail := node.Data[m[2]:m[3]]
  25. replaceContent(node, m[2], m[3], createLink(ctx, "mailto:"+mail, mail, "" /*mailto*/))
  26. node = node.NextSibling.NextSibling
  27. }
  28. }