add_tag: Wrap values in an HTML tag

Description Usage Arguments Value Examples

View source: R/html_misc.r

Description

Wrap values in an HTML tag

Usage

1
2
3
4
5
6
7
8
add_tag(
  x,
  tag,
  attr_str = NULL,
  ignore_na = F,
  span_adjacent = F,
  doc_id = NULL
)

Arguments

x

a vector of values to be wrapped in a tag

tag

A character vector of length 1, specifying the html tag (e.g., "div", "h1", "span")

attr_str

A character string of the same length as x (or of length 1).

ignore_na

If TRUE, do not add tag if value is NA

span_adjacent

If TRUE, include adjacent tokens with identical attr_str within the same tag

doc_id

If span_adjacent is TRUE, The document ids are required to ensure that tags do not span from one document to another.

Value

a character vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x = c("Obama","Bush")
add_tag(x, 'span')

## add attributes with the tag_attr function
add_tag(x, 'span',
        tag_attr(class = "president"))

## add style attributes with the attr_style function within tag_attr
add_tag(x, 'span',
        tag_attr(class = "president",
                 style = attr_style(`background-color` = 'rgba(255, 255, 0, 1)')))

kasperwelbers/tokenbrowser documentation built on May 3, 2021, 8:33 a.m.