html_tag: Tools for HTML tags

View source: R/string.R

html_tagR Documentation

Tools for HTML tags

Description

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, ...)

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 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.

.attrs

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().

x

A character vector to be treated as raw HTML content for html_value(), escaped for html_escape(), and viewed for html_view().

attr

Whether to escape ⁠"⁠, ⁠\r⁠, and ⁠\n⁠ (which should be escaped for tag attributes).

Value

A character string.

Examples

xfun::html_tag("a", "<R Project>", 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("<text>", xfun::html_tag("b", "R Project")), href = "#")
xfun::html_escape("\" quotes \" & brackets < >")
xfun::html_escape("\" & < > \r \n", attr = TRUE)

xfun documentation built on Nov. 1, 2024, 1:06 a.m.