mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
Refactor markup render system (#32612)
This PR removes (almost) all path tricks, and introduces "renderhelper" package. Now we can clearly see the rendering behaviors for comment/file/wiki, more details are in "renderhelper" tests. Fix #31411 , fix #18592, fix #25632 and maybe more problems. (ps: fix #32608 by the way)
This commit is contained in:
29
models/renderhelper/simple_document.go
Normal file
29
models/renderhelper/simple_document.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package renderhelper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
)
|
||||
|
||||
type SimpleDocument struct {
|
||||
*markup.SimpleRenderHelper
|
||||
ctx *markup.RenderContext
|
||||
baseLink string
|
||||
}
|
||||
|
||||
func (r *SimpleDocument) ResolveLink(link string, likeType markup.LinkType) string {
|
||||
return r.ctx.ResolveLinkRelative(r.baseLink, "", link)
|
||||
}
|
||||
|
||||
var _ markup.RenderHelper = (*SimpleDocument)(nil)
|
||||
|
||||
func NewRenderContextSimpleDocument(ctx context.Context, baseLink string) *markup.RenderContext {
|
||||
helper := &SimpleDocument{baseLink: baseLink}
|
||||
rctx := markup.NewRenderContext(ctx).WithHelper(helper).WithMetas(markup.ComposeSimpleDocumentMetas())
|
||||
helper.ctx = rctx
|
||||
return rctx
|
||||
}
|
Reference in New Issue
Block a user