mirror of
https://github.com/go-gitea/gitea
synced 2025-07-05 01:57:20 +00:00
Refactor markup render to fix various path problems (#34114)
* Fix #33972 * Use consistent path resolving for links and medias. * No need to make the markup renders to resolve the paths, instead, the paths are all correctly resolved in the "post process" step. * Fix #33274 * Since 1.23, all paths starting with "/" are relative to current render context (for example: the current repo branch) * Introduce `/:root/path-relative-to-root`, then the path will be rendered as relative to "ROOT_URL"
This commit is contained in:
@ -33,10 +33,24 @@ func resolveLinkRelative(ctx context.Context, base, cur, link string, absolute b
|
||||
return finalLink
|
||||
}
|
||||
|
||||
func (ctx *RenderContext) ResolveLinkRelative(base, cur, link string) (finalLink string) {
|
||||
func (ctx *RenderContext) ResolveLinkRelative(base, cur, link string) string {
|
||||
if strings.HasPrefix(link, "/:") {
|
||||
setting.PanicInDevOrTesting("invalid link %q, forgot to cut?", link)
|
||||
}
|
||||
return resolveLinkRelative(ctx, base, cur, link, ctx.RenderOptions.UseAbsoluteLink)
|
||||
}
|
||||
|
||||
func (ctx *RenderContext) ResolveLinkApp(link string) string {
|
||||
func (ctx *RenderContext) ResolveLinkRoot(link string) string {
|
||||
return ctx.ResolveLinkRelative(setting.AppSubURL+"/", "", link)
|
||||
}
|
||||
|
||||
func ParseRenderedLink(s, preferLinkType string) (linkType, link string) {
|
||||
if strings.HasPrefix(s, "/:") {
|
||||
p := strings.IndexByte(s[1:], '/')
|
||||
if p == -1 {
|
||||
return s, ""
|
||||
}
|
||||
return s[:p+1], s[p+2:]
|
||||
}
|
||||
return preferLinkType, s
|
||||
}
|
||||
|
Reference in New Issue
Block a user