Debian Codegraph @

man/html.Rd

raw
1 \name{html}
2 \alias{html}
3 \alias{print.html_elem}
4 \alias{as.character.html_elem}
5 \alias{c.html_elem}
6 \alias{html_group}
7 \alias{as.html_group}
8 \alias{as.character.html_group}
9 \alias{print.html_group}
10 \alias{[.html_group}
11 \alias{[<-.html_group}
12 \alias{c.html_group}
13
14 \alias{content}
15 \alias{content<-}
16 \alias{setContent}
17 \alias{attribs}
18 \alias{attribs<-}
19 \alias{setAttribs}
20 \alias{setAttribs.character}
21 \alias{setAttribs.html_elem}
22 \alias{setAttribs.html_group}
23 \alias{[<-.html_attributes}
24
25 \alias{css}
26 \alias{as.css}
27 \alias{style}
28 \alias{style<-}
29 \alias{setStyle}
30 \alias{setStyle.character}
31 \alias{setStyle.html_elem}
32 \alias{setStyle.html_group}
33 \alias{as.character.css}
34 \alias{print.css}
35 \alias{[<-.css}
36 \title{
37 Building Blocks for HTML Code
38 }
39 \description{
40 The functions described here form building blocks for
41 the \code{\link{format_html}} methods functions for \code{codebook},
42 \code{ftable}, \code{ftable_matrix}, and \code{mtable} objects, etc.
43
44 The most basic of these functions is \code{html}, which constructs an
45 object that represents a minimal piece of HTML code and is member of the
46 class \code{"html_elem"}. Unlike a character string containing HTML
47 code, the resulting code element can relatively easily modified using
48 other functions presented here. The actual code is created when the
49 function \code{as.character} is applied to these objects.
50
51 Longer sequences of HTML code can be prepared by
52 concatenating them with \code{c}, or by \code{html_group},
53 or by applying \code{as.html_group} to a list of
54 \code{"html_elem"} objects. All these result in objects
55 of class \code{"html_group"}.
56
57 Attributes (such as class, id etc.) of HTML elements can be added to the
58 call to \code{html}, but can also later recalled or modified with
59 \code{attribs} or \code{setAttribs}. An important attribute
60 is the style attribute, which can contain CSS styling. It can
61 be recalled or modified with \code{style} or \code{setStyle}. Styling
62 strings can also be created with \code{hmtl_style} or \code{as.css}
63
64 }
65 \usage{
66 html(tag, \dots, .content = NULL, linebreak = FALSE)
67 html_group(\dots)
68 as.html_group(x)
69
70 content(x)
71 content(x)<-value
72 setContent(x,value)
73
74 attribs(x)
75 attribs(x)<-value
76 setAttribs(x,\dots)
77 \method{setAttribs}{character}(x,\dots)
78 \method{setAttribs}{html_elem}(x,\dots)
79 \method{setAttribs}{html_group}(x,\dots)
80
81 css(\dots)
82 as.css(x)
83 style(x)
84 style(x) <- value
85 setStyle(x,\dots)
86 \method{setStyle}{character}(x,\dots)
87 \method{setStyle}{html_elem}(x,\dots)
88 \method{setStyle}{html_group}(x,\dots)
89 }
90 \arguments{
91 \item{tag}{a character string that determines the opening and closing
92 tags of the HTML element. (The closing tag is relevant only if
93 the element has a content.)}
94 \item{\dots}{optional further arguments, named or not.
95
96 For \code{html}: named arguments create the attributes of the HTML element,
97 unnamed arguments define the content of the HTML element, i.e. whatever
98 appears between opening and closing tags (e.g. \code{<p>} and \code{</p>}).
99 Character strings, \code{"html_elem"}, or \code{"html_group"} objects can appear
100 as content of a HTML element.
101
102 For \code{setAttribs}: named arguments create the attributes of the HTML element,
103 unnamed arguments are ignored.
104
105 For \code{setStyle}: named arguments create the styling of the HTML element,
106 unnamed arguments are ignored.
107
108 For \code{html_group}: several objects of class \code{"html_elem"}
109 or \code{"html_group"}.
110
111 For \code{css}: named arguments (character strings!)
112 become components of a styling in CSS format.
113 }
114 \item{.content}{an optional character string, \code{"html_elem"}, or
115 \code{"html_group"} object}
116 \item{linebreak}{a logical value or vector of length 2, determines
117 whether linebreaks are inserted after the HTML tags.}
118 \item{x}{an object. For \code{as.html_group}, this should be a list
119 of objects of class \code{"html_elem"} or \code{"html_group"}.
120 For \code{content}, \code{setContent}, \code{attribs},
121 \code{setAttribs}, \code{style}, \code{setStyle},
122 this should be an object of class \code{"html_elem"} or \code{"html_group"}.
123 }
124 \item{value}{an object of appropriate class.
125
126 For \code{content<-}: a character string, \code{"html_elem"}, or
127 \code{"html_group"} object, or a concatenation thereof.
128
129 For \code{attribs<-} or \code{style<-}: a named character vector.
130 }
131 }
132 \details{
133 Objects created with \code{html} are lists with class attribute
134 \code{"html_elem"} and components
135 \describe{
136 \item{tag}{a character string}
137 \item{attributes}{a named character vector}
138 \item{content}{a character vector, an \code{"html_elem"} or \code{"html_group"}
139 object, or a list of such.
140 }
141 \item{linebreak}{a logical value or vector of length 2.}
142 }
143 Objects created with \code{html_group} or by concatenation
144 of \code{"html_elem"} or \code{"html_group"}
145 object
146 are lists of such objects, with class attribute \code{"html_group"}.
147 }
148 \examples{
149
150 html("img")
151 html("img",src="test.png")
152 html("div",class="element",id="first","Sisyphus")
153 html("div",class="element",id="first",.content="Sisyphus")
154
155 div <- html("div",class="element",id="first",linebreak=c(TRUE,TRUE))
156 content(div) <- "Sisyphus"
157 div
158
159 tag <- html("tag",linebreak=TRUE)
160 attribs(tag)["class"] <- "something"
161 attribs(tag)["class"]
162 tag
163
164 style(tag) <- c(color="#342334")
165 style(tag)
166 tag
167
168 style(tag)["bg"] <- "white"
169 tag
170
171 setStyle(tag,bg="black")
172 setStyle(tag,c(bg="black"))
173
174 c(div,tag,tag)
175
176 c(
177 c(div,tag),
178 c(div,tag,tag)
179 )
180
181 c(
182 c(div,tag),
183 div,tag,tag
184 )
185
186 c(
187 div,tag,
188 c(div,tag,tag)
189 )
190
191 content(div) <- c(tag,tag,tag)
192 div
193
194
195 css("background-color"="black",
196 color="white")
197
198 as.css(c("background-color"="black",
199 color="white"))
200
201
202
203 Hello <- "Hello World!"
204 Hello <- html("p",Hello,linebreak=c(TRUE,TRUE))
205 style(Hello) <- c(color="white",
206 "font-size"="40px",
207 "text-align"="center")
208
209 Link <- html("a","More examples here ...",
210 href="http://elff.eu/software/memisc",
211 title="More examples here ...",
212 style=css(color="white"),
213 linebreak=c(TRUE,FALSE))
214 Link <- html("p"," (",Link,")",linebreak=c(TRUE,TRUE))
215 style(Link) <- c(color="white",
216 "font-size"="15px",
217 "text-align"="center")
218
219 Hello <- html("div",c(Hello,Link),linebreak=c(TRUE,TRUE))
220 style(Hello) <- c("background-color"="#160666",
221 padding="20px")
222 Hello
223
224 show_html(Hello)
225
226 }