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, ...)
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).
A character string.
xfun::html_tag("a", "<R Project>", href = "https://www.r-project.org", target = "_blank")
#> <a href="https://www.r-project.org" target="_blank"><R Project></a>
xfun::html_tag("br")
#> <br />
xfun::html_tag("a", xfun::html_tag("strong", "R Project"), href = "#")
#> <a href="#"><strong>R Project</strong></a>
xfun::html_tag("a", list("<text>", xfun::html_tag("b", "R Project")), href = "#")
#> <a href="#"><text><b>R Project</b></a>
xfun::html_escape("\" quotes \" & brackets < >")
#> [1] "\" quotes \" & brackets < >"
xfun::html_escape("\" & < > \r \n", attr = TRUE)
#> [1] "" & < > "