You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Use `html.ParseFragment` to parse a fragment of HTML where the root elements are
`<tbody>`, `<tr>` or `<td>` (and probably other table sub-elements)
For example:
s := `<td>first</td>
<td>second</td>
<td>third</td>
`
doc, err := html.ParseFragment(strings.NewReader(s), &html.Node{
Type: html.ElementNode,
Data: "body",
DataAtom: atom.Body,
})
2. Check the result `fmt.Printf("%#v\n", doc)`
What is the expected output?
`[]*html.Node` of 3 `td` elements
What do you see instead?
`[]*html.Node` of a single text node containing the `first second third` text.
Which operating system are you using? Linux
Which version are you using? 1.2
ParseFragment works fine with other semantically incorrect structures, like
`<option>` elements. Has trouble with table sub-elements though.
If this isn't a bug and is failing by design, perhaps we need something like
`atom.DocumentFragment` that will receive any arbitrary HTML.
The text was updated successfully, but these errors were encountered:
It is working as intended, since it parses it just as it would if the fragment were
enclosed between <body> and </body>. But it does surprise people.
A ParseFragment-like function that does not take a context, and tries to return the
parse tree that a user is likely to expect, would be nice. It would probably require
adding a new insertion mode to the parser, though, so it wouldn't be trivial.
mikioh
changed the title
code.google.com/p/go.net/html: ParseFragment fails to parse sub-table elements in the root position
x/net/html: ParseFragment fails to parse sub-table elements in the root position
Dec 23, 2014
mikioh
changed the title
x/net/html: ParseFragment fails to parse sub-table elements in the root position
html: ParseFragment fails to parse sub-table elements in the root position
Jan 4, 2015
rsc
changed the title
html: ParseFragment fails to parse sub-table elements in the root position
x/net/html: ParseFragment fails to parse sub-table elements in the root position
Apr 14, 2015
by algorithmicimperative:
The text was updated successfully, but these errors were encountered: