diff --git a/modules/markup/html.go b/modules/markup/html.go index 8851558286..b4fd008aa7 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -1086,7 +1086,8 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) { // Specialized version of replaceContent, so the parent paragraph element is not destroyed from our div before := node.Data[:(preview.start - offset)] after := node.Data[(preview.end - offset):] - offset += preview.end - 3 + afterPrefix := "
" + offset = preview.end - len(afterPrefix) node.Data = before nextSibling := node.NextSibling node.Parent.InsertBefore(&html.Node{ @@ -1096,7 +1097,7 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) { node.Parent.InsertBefore(previewNode, nextSibling) afterNode := &html.Node{ Type: html.RawNode, - Data: "
" + after, + Data: afterPrefix + after, } node.Parent.InsertBefore(afterNode, nextSibling) node = afterNode diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 1b8a92e51f..a1a99c1a7f 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -917,5 +917,86 @@ func TestRender_FilePreview(t *testing.T) { `
`, localMetas, ) + + testRender( + "first "+commitFilePreview+" second "+commitFilePreview+" third "+commitFilePreview, + `first
`+ + ``+ + ` | B`+"\n"+` | `+
+ `
`+ + ` | C`+"\n"+` | `+
+ `
second
`+ + ``+ + ` | B`+"\n"+` | `+
+ `
`+ + ` | C`+"\n"+` | `+
+ `
third
`+ + ``+ + ` | B`+"\n"+` | `+
+ `
`+ + ` | C`+"\n"+` | `+
+ `