Skip to contents

Parses markup as the contents of a given element, as a browser does for innerHTML. The context matters: "<tr><td>x" is a table row in a "tbody" context but only text in a "div".

Usage

html_fragment(x, context = "div", ...)

Arguments

x

One string, or a raw vector of encoded bytes.

context

The name of the context element, an HTML element the bundled parser knows, such as "div", "tbody", "select" or "template".

...

Arguments passed on to html_parse(): encoding, base_url, comments and limits.

Value

A zuhtml_document whose document node is a fragment: html_type() reports "fragment", and html_root() returns the fragment node, whose children are the parsed nodes.

See also

Examples

frag <- html_fragment("<tr><td>1<td>2", context = "tbody")
html_children(html_root(frag))
#> <zuhtml_nodeset[1]>
#> [1] <tr>
html_fragment("<tr><td>1<td>2")
#> <zuhtml_document>
#> fragment: in <div>
#> nodes:    2
#> input:    14 bytes (UTF-8)
#> problems: 3