| html_serialize | R Documentation |
Produces normalized HTML following the WHATWG serialization algorithm,
not the original input bytes: end tags the input left out are written,
attribute values are always double-quoted, and &, <, >, " and
non-breaking spaces are escaped as the algorithm requires. Parsing the
result gives back the same tree, except where the HTML standard itself
does not guarantee that (for example markup that tree construction
rearranges).
html_serialize(x, outer = TRUE, pretty = FALSE)
x |
A |
outer |
If |
pretty |
If |
Serialization is not sanitization: <script> elements and
javascript: URLs are written as they were parsed.
as.character() on a nodeset is html_serialize().
A character vector as long as x; NA for missing nodes.
Other node values:
html_attr(),
html_markdown(),
html_name(),
html_strings(),
html_text(),
html_text_clean()
doc <- html_parse("<p class=x>One<br>Two & <b>three</p>")
html_serialize(doc)
p <- html_children(html_children(html_root(doc))[2])
html_serialize(p)
html_serialize(p, outer = FALSE)
cat(html_serialize(doc, pretty = TRUE))
# To write a document to a file:
path <- tempfile(fileext = ".html")
writeLines(html_serialize(doc), path)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.