mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-04 13:50:11 +00:00
Some checks failed
testing / frontend-checks (push) Has been skipped
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Integration tests for the release process / release-simulation (push) Has been cancelled
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/7337 - Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7354 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package markdown
|
|
|
|
import (
|
|
"bytes"
|
|
"slices"
|
|
|
|
"forgejo.org/modules/markup"
|
|
"forgejo.org/modules/setting"
|
|
giteautil "forgejo.org/modules/util"
|
|
|
|
"github.com/yuin/goldmark/ast"
|
|
)
|
|
|
|
func (g *ASTTransformer) transformLink(ctx *markup.RenderContext, v *ast.Link) {
|
|
// Links need their href to munged to be a real value
|
|
link := v.Destination
|
|
|
|
// Do not process the link if it's not a link, starts with an hashtag
|
|
// (indicating it's an anchor link), starts with `mailto:` or any of the
|
|
// custom markdown URLs.
|
|
processLink := len(link) > 0 && !markup.IsLink(link) &&
|
|
link[0] != '#' && !bytes.HasPrefix(link, byteMailto) &&
|
|
!slices.ContainsFunc(setting.Markdown.CustomURLSchemes, func(s string) bool {
|
|
return bytes.HasPrefix(link, []byte(s+":"))
|
|
})
|
|
|
|
if processLink {
|
|
var base string
|
|
if ctx.IsWiki {
|
|
base = ctx.Links.WikiLink()
|
|
} else if ctx.Links.HasBranchInfo() {
|
|
base = ctx.Links.SrcLink()
|
|
} else {
|
|
base = ctx.Links.Base
|
|
}
|
|
|
|
link = []byte(giteautil.URLJoin(base, string(link)))
|
|
}
|
|
if len(link) > 0 && link[0] == '#' {
|
|
link = []byte("#user-content-" + string(link)[1:])
|
|
}
|
|
v.Destination = link
|
|
}
|