diff options
author | zeripath <art27@cantab.net> | 2021-06-21 23:12:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 00:12:22 +0200 |
commit | d55b5eb0d3f1d129eb4d03cc7ddb56a59b4db8ff (patch) | |
tree | f42a4e6d32c910bdbc6ab920d07e89fa75169173 | |
parent | 36c158bc9375d7ebb9aa749ccd6718d0d68e96d2 (diff) | |
download | gitea-d55b5eb0d3f1d129eb4d03cc7ddb56a59b4db8ff.tar.gz gitea-d55b5eb0d3f1d129eb4d03cc7ddb56a59b4db8ff.zip |
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>
-rw-r--r-- | modules/markup/html.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go index edf860da45..0cc0e23b5c 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -304,27 +304,26 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output _, _ = res.WriteString("</body></html>") // parse the HTML - nodes, err := html.ParseFragment(res, nil) + node, err := html.Parse(res) if err != nil { return &postProcessError{"invalid HTML", err} } - for _, node := range nodes { - visitNode(ctx, procs, node, true) + if node.Type == html.DocumentNode { + node = node.FirstChild } - newNodes := make([]*html.Node, 0, len(nodes)) + visitNode(ctx, procs, node, true) - for _, node := range nodes { - if node.Data == "html" { - node = node.FirstChild - for node != nil && node.Data != "body" { - node = node.NextSibling - } - } - if node == nil { - continue + newNodes := make([]*html.Node, 0, 5) + + if node.Data == "html" { + node = node.FirstChild + for node != nil && node.Data != "body" { + node = node.NextSibling } + } + if node != nil { if node.Data == "body" { child := node.FirstChild for child != nil { |