Debian Codegraph @

R/hooks-textile.R

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