You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markdown
  4. import (
  5. "code.gitea.io/gitea/modules/markup"
  6. giteautil "code.gitea.io/gitea/modules/util"
  7. "github.com/yuin/goldmark/ast"
  8. "github.com/yuin/goldmark/text"
  9. )
  10. func (g *ASTTransformer) transformLink(ctx *markup.RenderContext, v *ast.Link, reader text.Reader) {
  11. // Links need their href to munged to be a real value
  12. link := v.Destination
  13. isAnchorFragment := len(link) > 0 && link[0] == '#'
  14. if !isAnchorFragment && !markup.IsFullURLBytes(link) {
  15. base := ctx.Links.Base
  16. if ctx.IsWiki {
  17. base = ctx.Links.WikiLink()
  18. } else if ctx.Links.HasBranchInfo() {
  19. base = ctx.Links.SrcLink()
  20. }
  21. link = []byte(giteautil.URLJoin(base, string(link)))
  22. }
  23. if isAnchorFragment {
  24. link = []byte("#user-content-" + string(link)[1:])
  25. }
  26. v.Destination = link
  27. }