| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/string.R |
| 3 |
\name{html_tag} |
| 4 |
\alias{html_tag} |
| 5 |
\alias{html_value} |
| 6 |
\alias{html_escape} |
| 7 |
\alias{html_view} |
| 8 |
\title{Tools for HTML tags} |
| 9 |
\usage{ |
| 10 |
html_tag(.name, .content = NULL, .attrs = NULL, ...) |
| 11 |
|
| 12 |
html_value(x) |
| 13 |
|
| 14 |
html_escape(x, attr = FALSE) |
| 15 |
|
| 16 |
html_view(x, name = "xfun-html", ...) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{.name}{The tag name.} |
| 20 |
|
| 21 |
\item{.content}{The content between opening and closing tags. Ignored for |
| 22 |
void tags such as \verb{<img>}. Special characters such as \code{&}, \code{<}, and \code{>} |
| 23 |
will be escaped unless the value was generated from \code{\link[=html_value]{html_value()}}. The |
| 24 |
content can be either a character vector or a list. If it is a list, it may |
| 25 |
contain both normal text and HTML content.} |
| 26 |
|
| 27 |
\item{.attrs}{A named list of attributes.} |
| 28 |
|
| 29 |
\item{...}{For \code{html_tag()}, named arguments as an alternative way to provide |
| 30 |
attributes. For \code{html_view()}, other arguments to be passed to \code{\link[=new_app]{new_app()}}.} |
| 31 |
|
| 32 |
\item{x}{A character vector to be treated as raw HTML content for |
| 33 |
\code{html_value()}, escaped for \code{html_escape()}, and viewed for \code{html_view()}.} |
| 34 |
|
| 35 |
\item{attr}{Whether to escape \verb{"}, \verb{\\r}, and \verb{\\n} (which should be escaped |
| 36 |
for tag attributes).} |
| 37 |
|
| 38 |
\item{name}{The app name passed to \code{\link[=new_app]{new_app()}}.} |
| 39 |
} |
| 40 |
\value{ |
| 41 |
A character string. |
| 42 |
} |
| 43 |
\description{ |
| 44 |
Given a tag name, generate an HTML tag with optional attributes and content. |
| 45 |
\code{\link[=html_tag]{html_tag()}} can be viewed as a simplified version of \code{htmltools::tags}, |
| 46 |
\code{\link[=html_value]{html_value()}} adds classes on the value so that it will be treated as raw |
| 47 |
HTML (not escaped by \code{html_tag()}), \code{\link[=html_escape]{html_escape()}} escapes special |
| 48 |
characters in HTML, and \code{html_view()} launches a browser or viewer to view |
| 49 |
the HTML content. |
| 50 |
} |
| 51 |
\examples{ |
| 52 |
xfun::html_tag("a", "<R Project>", href = "https://www.r-project.org", target = "_blank") |
| 53 |
xfun::html_tag("br") |
| 54 |
xfun::html_tag("a", xfun::html_tag("strong", "R Project"), href = "#") |
| 55 |
xfun::html_tag("a", list("<text>", xfun::html_tag("b", "R Project")), href = "#") |
| 56 |
xfun::html_escape("\" quotes \" & brackets < >") |
| 57 |
xfun::html_escape("\" & < > \r \n", attr = TRUE) |
| 58 |
} |