mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-20 19:11:09 +09:00
Only turn links to current instance into hash links (#36237)
Given the following markdown: ```a832c723cd19fe6cdf81a832c723cd``` Previously, all links would turn into hash link, even ones to external sites: <img width="849" height="89" alt="Screenshot 2025-12-23 at 19 19 13" src="https://github.com/user-attachments/assets/2ad35a18-4542-40a4-a838-7ab8ac8bc047" /> After this change, only links to the current instance, as identified by `setting.AppURL` are turned into hash links: <img width="850" height="87" alt="Screenshot 2025-12-23 at 19 18 56" src="https://github.com/user-attachments/assets/2c49a5b2-426c-4a82-a610-9b9da8dcfff9" /> There is still one notable [difference with GitHub](https://github.com/silverwind/symlink-test/issues/20#issuecomment-3687535938) where the second link should render like `user/repo@<hash>`, not `<hash>` as currently, I would like to fix that here as well. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
@@ -121,6 +122,11 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||
if ret.QueryHash != "" {
|
||||
text += " (" + ret.QueryHash + ")"
|
||||
}
|
||||
// only turn commit links to the current instance into hash link
|
||||
if !httplib.IsCurrentGiteaSiteURL(ctx, ret.FullURL) {
|
||||
node = node.NextSibling
|
||||
continue
|
||||
}
|
||||
replaceContent(node, ret.PosStart, ret.PosEnd, createCodeLink(ret.FullURL, text, "commit"))
|
||||
node = node.NextSibling.NextSibling
|
||||
}
|
||||
@@ -167,6 +173,12 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||
}
|
||||
}
|
||||
|
||||
// only turn compare links to the current instance into hash link
|
||||
if !httplib.IsCurrentGiteaSiteURL(ctx, urlFull) {
|
||||
node = node.NextSibling
|
||||
continue
|
||||
}
|
||||
|
||||
text := text1 + textDots + text2
|
||||
if hash != "" {
|
||||
text += " (" + hash + ")"
|
||||
|
||||
Reference in New Issue
Block a user