Given a tag name, generate an HTML tag with optional attributes and content.
html_tag()
can be viewed as a simplified version of htmltools::tags
,
html_value()
adds classes on the value so that it will be treated as raw
HTML (not escaped by html_tag()
), html_escape()
escapes special
characters in HTML, and html_view()
launches a browser or viewer to view
the HTML content.
html_tag(.name, .content = NULL, .attrs = NULL, ...)html_value(x)
html_escape(x, attr = FALSE)
html_view(x, ...)
A character string.
The tag name.
The content between opening and closing tags. Ignored for
void tags such as <img>
. Special characters such as &
, <
, and >
will be escaped unless the value was generated from html_value()
. The
content can be either a character vector or a list. If it is a list, it may
contain both normal text and HTML content.
A named list of attributes.
For html_tag()
, named arguments as an alternative way to provide
attributes. For html_view()
, other arguments to be passed to new_app()
.
A character vector to be treated as raw HTML content for
html_value()
, escaped for html_escape()
, and viewed for html_view()
.
Whether to escape "
, \r
, and \n
(which should be escaped
for tag attributes).
xfun::html_tag("a", "", href = "https://www.r-project.org", target = "_blank")
xfun::html_tag("br")
xfun::html_tag("a", xfun::html_tag("strong", "R Project"), href = "#")
xfun::html_tag("a", list("", xfun::html_tag("b", "R Project")), href = "#")
xfun::html_escape("\" quotes \" & brackets < >")
xfun::html_escape("\" & < > \r \n", attr = TRUE)
Run the code above in your browser using DataLab