m: Generic representaion of an HTML tag in R

Description Usage Arguments Value Examples

View source: R/html.R

Description

Render arguments to a string of markup (HTML but also generic XML)

Usage

1
2
3
  m(tag, ..., opts = list(),
    specials = list(id = "#", class = "\."),
    escape.html.p = FALSE, singleton = FALSE)

Arguments

tag

character The name of the html/xml tag to be used

...

the content of the tag. Eventually coerced into character vector. Can be list or function

opts

list of key=values for tag attributes

specials

list of shortcuts for setting ID and class attributes. Should be familiar to css users. Potentially extendable to to other attributes...

escape.html.p

logical predicate. Should all html be escaped? calls escape.html() on the final character output if TRUE

singleton

logical predicate. If TRUE the tag is of form <tag body>

Value

a character vector of length 1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
m("p")
m("div")
# Any strings after that become the content of the tag
m("p", "This is a paragraph")
# Tags can be nested inside of tags and everything ends up concatenated
m("p", "Goodbye", m("strong", "cruel"), "world")
# You can specify attributes by supplying a list after the content
m("span",  "bar", opts = list(class = "foo"))
#' There are CSS-style shortcuts for setting ID and class
m("p#my-p", m("span.pretty", "hey"))
m("span", opts = list(id = "foo", class = "bar"), "baz")
# You can escape a string using the (escape-html) function
m("p", m("script", "Do something evil", escape.html.p = TRUE))
# Also caters for singleton tags:
m("meta", opts = list(charset = "utf-8"), singleton = TRUE)
}

DASpringate/samatha documentation built on May 6, 2019, 1:16 p.m.