mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
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.
32 lines
868 B
32 lines
868 B
8 months ago
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
package markdown
|
||
|
|
||
|
import (
|
||
|
"code.gitea.io/gitea/modules/markup"
|
||
|
giteautil "code.gitea.io/gitea/modules/util"
|
||
|
|
||
|
"github.com/yuin/goldmark/ast"
|
||
|
"github.com/yuin/goldmark/text"
|
||
|
)
|
||
|
|
||
|
func (g *ASTTransformer) transformLink(ctx *markup.RenderContext, v *ast.Link, reader text.Reader) {
|
||
|
// Links need their href to munged to be a real value
|
||
|
link := v.Destination
|
||
|
isAnchorFragment := len(link) > 0 && link[0] == '#'
|
||
|
if !isAnchorFragment && !markup.IsFullURLBytes(link) {
|
||
|
base := ctx.Links.Base
|
||
|
if ctx.IsWiki {
|
||
|
base = ctx.Links.WikiLink()
|
||
|
} else if ctx.Links.HasBranchInfo() {
|
||
|
base = ctx.Links.SrcLink()
|
||
|
}
|
||
|
link = []byte(giteautil.URLJoin(base, string(link)))
|
||
|
}
|
||
|
if isAnchorFragment {
|
||
|
link = []byte("#user-content-" + string(link)[1:])
|
||
|
}
|
||
|
v.Destination = link
|
||
|
}
|