Skip to content

Commit

Permalink
Use html.Parse rather than html.ParseFragment (#16223)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
zeripath authored Jun 21, 2021
1 parent 36c158b commit d55b5eb
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d55b5eb

Please sign in to comment.