forked from yihui/knitr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks-textile.R
45 lines (41 loc) · 1.3 KB
/
hooks-textile.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' @rdname hook_plot
#' @export
hook_plot_textile = function(x, options) {
cap = .img.cap(options); if (is.na(cap)) cap = ''
tags = unlist(c(Map(
sprintf, c('width: %s', 'height: %s'),
options[c('out.width', 'out.height')]
), css_align(options$fig.align)))
tags = if (length(tags)) sprintf('{%s}', paste(tags, collapse = ';')) else ''
paste0(
'!', tags, opts_knit$get('base.url'), .upload.url(x),
if (nzchar(cap)) sprintf('(%s)', cap), '!\n\n',
if (nzchar(cap)) sprintf('p(knitr plot caption#%s). %s', options$label, cap),
'\n\n'
)
}
#' @rdname output_hooks
#' @export
render_textile = function() {
set_html_dev()
opts_knit$set(out.format = 'textile')
knit_hooks$set(hooks_textile())
}
#' @rdname output_hooks
#' @export
hooks_textile = function() {
hook = function(name) {
force(name)
function(x, options) {
if (name == 'source') x = c(hilight_source(x, 'textile', options), '')
x = one_string(x)
sprintf('bc(knitr %s %s#%s).. %s\np(knitr_end). \n\n',
tolower(options$engine), name, options$label, x)
}
}
list(
source = hook('source'), output = hook('output'), warning = hook('warning'),
message = hook('message'), error = hook('error'), plot = hook_plot_textile,
inline = function(x) .inline.hook(format_sci(x, 'html'))
)
}