forked from forgejo/forgejo
Fix issue where rendering stops after the first invalid parmalink
This commit is contained in:
parent
5b6b3f3fb3
commit
e9eacdecd2
3 changed files with 77 additions and 28 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue