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.
Usage
html_tag(.name, .content = NULL, .attrs = NULL, ...)
html_value(x)
html_escape(x, attr = FALSE)
html_view(x, name = "xfun-html", ...)Arguments
- .name
The tag name.
- .content
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 fromhtml_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.- .attrs
A named list of attributes.
- ...
For
html_tag(), named arguments as an alternative way to provide attributes. Forhtml_view(), other arguments to be passed tonew_app().- x
A character vector to be treated as raw HTML content for
html_value(), escaped forhtml_escape(), and viewed forhtml_view().- attr
Whether to escape
",\r, and\n(which should be escaped for tag attributes).- name
The app name passed to
new_app().
Examples
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] "" & < > "