1
0
Fork 0
forked from forgejo/forgejo

Fix issue where rendering stops after the first invalid parmalink

This commit is contained in:
Mai-Lapyst 2024-04-19 18:21:21 +02:00
parent 5b6b3f3fb3
commit e9eacdecd2
No known key found for this signature in database
GPG key ID: F88D929C09E239F8
3 changed files with 77 additions and 28 deletions

View file

@ -35,24 +35,36 @@ type FilePreview struct {
isTruncated bool
}
func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Locale) *FilePreview {
func NewFilePreviews(ctx *RenderContext, node *html.Node, locale translation.Locale) []*FilePreview {
if setting.FilePreviewMaxLines == 0 {
// Feature is disabled
return nil
}
mAll := filePreviewPattern.FindAllStringSubmatchIndex(node.Data, -1)
if mAll == nil {
return nil
}
result := make([]*FilePreview, 0)
for _, m := range mAll {
if slices.Contains(m, -1) {
continue
}
preview := newFilePreview(ctx, node, locale, m)
if preview != nil {
result = append(result, preview)
}
}
return result
}
func newFilePreview(ctx *RenderContext, node *html.Node, locale translation.Locale, m []int) *FilePreview {
preview := &FilePreview{}
m := filePreviewPattern.FindStringSubmatchIndex(node.Data)
if m == nil {
return nil
}
// Ensure that every group has a match
if slices.Contains(m, -1) {
return nil
}
urlFull := node.Data[m[0]:m[1]]
// Ensure that we only use links to local repositories