mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-09-08 08:33:27 +00:00
Use html.Parse rather than html.ParseFragment (#16223)
* Use html.Parse rather than html.ParseFragment There have been a few issues with html.ParseFragment - just use html.Parse instead. * Skip document node Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
36c158bc93
commit
d55b5eb0d3
1 changed files with 12 additions and 13 deletions
|
@ -304,27 +304,26 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
|
||||||
_, _ = res.WriteString("</body></html>")
|
_, _ = res.WriteString("</body></html>")
|
||||||
|
|
||||||
// parse the HTML
|
// parse the HTML
|
||||||
nodes, err := html.ParseFragment(res, nil)
|
node, err := html.Parse(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &postProcessError{"invalid HTML", err}
|
return &postProcessError{"invalid HTML", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodes {
|
if node.Type == html.DocumentNode {
|
||||||
visitNode(ctx, procs, node, true)
|
node = node.FirstChild
|
||||||
}
|
}
|
||||||
|
|
||||||
newNodes := make([]*html.Node, 0, len(nodes))
|
visitNode(ctx, procs, node, true)
|
||||||
|
|
||||||
|
newNodes := make([]*html.Node, 0, 5)
|
||||||
|
|
||||||
for _, node := range nodes {
|
|
||||||
if node.Data == "html" {
|
if node.Data == "html" {
|
||||||
node = node.FirstChild
|
node = node.FirstChild
|
||||||
for node != nil && node.Data != "body" {
|
for node != nil && node.Data != "body" {
|
||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node == nil {
|
if node != nil {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if node.Data == "body" {
|
if node.Data == "body" {
|
||||||
child := node.FirstChild
|
child := node.FirstChild
|
||||||
for child != nil {
|
for child != nil {
|
||||||
|
|
Loading…
Reference in a new issue