forked from forgejo/forgejo
[v7.0/forgejo] Render inline file permalinks
Backport: https://codeberg.org/forgejo/forgejo/pulls/2669 (cherry picked from commit1d3240887c
) (cherry picked from commit781a37fbe1
) (cherry picked from commit8309f008c2
) (cherry picked from commitfae8d9f70d
) (cherry picked from commit6721cba75b
) (cherry picked from commit562e5cdf32
) (cherry picked from commitd789d33229
) (cherry picked from commit8218e80bfc
) (cherry picked from commit10bca456a9
) (cherry picked from commitdb6f6281fc
) (cherry picked from commited8e8a792e
) (cherry picked from commitd6428f92ce
) (cherry picked from commit069d87b80f
) (cherry picked from commit2b6546adc9
) (cherry picked from commit4c7cb0a5d2
) (cherry picked from commit7e0014dd13
) (cherry picked from commit16a8658878
) (cherry picked from commit6e98bacbbd
)
This commit is contained in:
parent
9f80081795
commit
22aedc6c96
25 changed files with 577 additions and 4 deletions
|
@ -171,6 +171,7 @@ type processor func(ctx *RenderContext, node *html.Node)
|
|||
var defaultProcessors = []processor{
|
||||
fullIssuePatternProcessor,
|
||||
comparePatternProcessor,
|
||||
filePreviewPatternProcessor,
|
||||
fullHashPatternProcessor,
|
||||
shortLinkProcessor,
|
||||
linkProcessor,
|
||||
|
@ -1054,6 +1055,47 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
|
|||
}
|
||||
}
|
||||
|
||||
func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||
if ctx.Metas == nil {
|
||||
return
|
||||
}
|
||||
if DefaultProcessorHelper.GetRepoFileBlob == nil {
|
||||
return
|
||||
}
|
||||
|
||||
next := node.NextSibling
|
||||
for node != nil && node != next {
|
||||
locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
|
||||
if !ok {
|
||||
locale = translation.NewLocale("en-US")
|
||||
}
|
||||
|
||||
preview := NewFilePreview(ctx, node, locale)
|
||||
if preview == nil {
|
||||
return
|
||||
}
|
||||
|
||||
previewNode := preview.CreateHTML(locale)
|
||||
|
||||
// Specialized version of replaceContent, so the parent paragraph element is not destroyed from our div
|
||||
before := node.Data[:preview.start]
|
||||
after := node.Data[preview.end:]
|
||||
node.Data = before
|
||||
nextSibling := node.NextSibling
|
||||
node.Parent.InsertBefore(&html.Node{
|
||||
Type: html.RawNode,
|
||||
Data: "</p>",
|
||||
}, nextSibling)
|
||||
node.Parent.InsertBefore(previewNode, nextSibling)
|
||||
node.Parent.InsertBefore(&html.Node{
|
||||
Type: html.RawNode,
|
||||
Data: "<p>" + after,
|
||||
}, nextSibling)
|
||||
|
||||
node = node.NextSibling
|
||||
}
|
||||
}
|
||||
|
||||
// emojiShortCodeProcessor for rendering text like :smile: into emoji
|
||||
func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
|
||||
start := 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue