html_fragment: Parse an HTML fragment

View source: R/parse.R

html_fragmentR Documentation

Parse an HTML fragment

Description

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

html_parse() for whole documents.

Other parsing: html_info(), html_limits(), html_parse(), html_problems(), zuhtml_info()

Examples

frag <- html_fragment("<tr><td>1<td>2", context = "tbody")
html_children(html_root(frag))
html_fragment("<tr><td>1<td>2")

zuhtml documentation built on Oct. 6, 2026, 5:06 p.m.