mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-27 12:53:57 +01:00
Fix panic where now a third link breaks everything
This commit is contained in:
parent
e9eacdecd2
commit
acfae43253
2 changed files with 84 additions and 2 deletions
|
@ -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
|
// Specialized version of replaceContent, so the parent paragraph element is not destroyed from our div
|
||||||
before := node.Data[:(preview.start - offset)]
|
before := node.Data[:(preview.start - offset)]
|
||||||
after := node.Data[(preview.end - offset):]
|
after := node.Data[(preview.end - offset):]
|
||||||
offset += preview.end - 3
|
afterPrefix := "<p>"
|
||||||
|
offset = preview.end - len(afterPrefix)
|
||||||
node.Data = before
|
node.Data = before
|
||||||
nextSibling := node.NextSibling
|
nextSibling := node.NextSibling
|
||||||
node.Parent.InsertBefore(&html.Node{
|
node.Parent.InsertBefore(&html.Node{
|
||||||
|
@ -1096,7 +1097,7 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
node.Parent.InsertBefore(previewNode, nextSibling)
|
node.Parent.InsertBefore(previewNode, nextSibling)
|
||||||
afterNode := &html.Node{
|
afterNode := &html.Node{
|
||||||
Type: html.RawNode,
|
Type: html.RawNode,
|
||||||
Data: "<p>" + after,
|
Data: afterPrefix + after,
|
||||||
}
|
}
|
||||||
node.Parent.InsertBefore(afterNode, nextSibling)
|
node.Parent.InsertBefore(afterNode, nextSibling)
|
||||||
node = afterNode
|
node = afterNode
|
||||||
|
|
|
@ -917,5 +917,86 @@ func TestRender_FilePreview(t *testing.T) {
|
||||||
`<p></p>`,
|
`<p></p>`,
|
||||||
localMetas,
|
localMetas,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
testRender(
|
||||||
|
"first "+commitFilePreview+" second "+commitFilePreview+" third "+commitFilePreview,
|
||||||
|
`<p>first </p>`+
|
||||||
|
`<div class="file-preview-box">`+
|
||||||
|
`<div class="header">`+
|
||||||
|
`<div>`+
|
||||||
|
`<a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20/path/to/file.go#L2-L3" class="muted" rel="nofollow">path/to/file.go</a>`+
|
||||||
|
`</div>`+
|
||||||
|
`<span class="text small grey">`+
|
||||||
|
`Lines 2 to 3 in <a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" class="text black" rel="nofollow">190d949</a>`+
|
||||||
|
`</span>`+
|
||||||
|
`</div>`+
|
||||||
|
`<div class="ui table">`+
|
||||||
|
`<table class="file-preview">`+
|
||||||
|
`<tbody>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="2"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">B</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="3"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">C</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`</tbody>`+
|
||||||
|
`</table>`+
|
||||||
|
`</div>`+
|
||||||
|
`</div>`+
|
||||||
|
`<p> second </p>`+
|
||||||
|
`<div class="file-preview-box">`+
|
||||||
|
`<div class="header">`+
|
||||||
|
`<div>`+
|
||||||
|
`<a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20/path/to/file.go#L2-L3" class="muted" rel="nofollow">path/to/file.go</a>`+
|
||||||
|
`</div>`+
|
||||||
|
`<span class="text small grey">`+
|
||||||
|
`Lines 2 to 3 in <a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" class="text black" rel="nofollow">190d949</a>`+
|
||||||
|
`</span>`+
|
||||||
|
`</div>`+
|
||||||
|
`<div class="ui table">`+
|
||||||
|
`<table class="file-preview">`+
|
||||||
|
`<tbody>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="2"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">B</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="3"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">C</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`</tbody>`+
|
||||||
|
`</table>`+
|
||||||
|
`</div>`+
|
||||||
|
`</div>`+
|
||||||
|
`<p> third </p>`+
|
||||||
|
`<div class="file-preview-box">`+
|
||||||
|
`<div class="header">`+
|
||||||
|
`<div>`+
|
||||||
|
`<a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20/path/to/file.go#L2-L3" class="muted" rel="nofollow">path/to/file.go</a>`+
|
||||||
|
`</div>`+
|
||||||
|
`<span class="text small grey">`+
|
||||||
|
`Lines 2 to 3 in <a href="http://localhost:3000/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" class="text black" rel="nofollow">190d949</a>`+
|
||||||
|
`</span>`+
|
||||||
|
`</div>`+
|
||||||
|
`<div class="ui table">`+
|
||||||
|
`<table class="file-preview">`+
|
||||||
|
`<tbody>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="2"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">B</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`<tr>`+
|
||||||
|
`<td class="lines-num"><span data-line-number="3"></span></td>`+
|
||||||
|
`<td class="lines-code chroma"><code class="code-inner"><span class="nx">C</span>`+"\n"+`</code></td>`+
|
||||||
|
`</tr>`+
|
||||||
|
`</tbody>`+
|
||||||
|
`</table>`+
|
||||||
|
`</div>`+
|
||||||
|
`</div>`+
|
||||||
|
`<p></p>`,
|
||||||
|
localMetas,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue