Debian Codegraph @

R/rocco.R

raw
1 #' Knit R Markdown using the classic Docco style
2 #'
3 #' The classic Docco style is a two-column layout, with text in the left and
4 #' code in the right column.
5 #'
6 #' The output HTML page supports resizing and hiding/showing the two columns.
7 #' Move the cursor to the center of the page, and it will change to a
8 #' bidirectional resize cursor; drag the cursor to resize the two columns. Press
9 #' the key \code{t} to hide the code column (show the text column only), and
10 #' press again to hide the text column (show code).
11 #' @param input Path of the input R Markdown file.
12 #' @param ... Arguments to be passed to \code{\link{knit2html}}
13 #' @return An HTML file is written, and its name is returned.
14 #' @author Weicheng Zhu and Yihui Xie
15 #' @references The Docco package by Jeremy Ashkenas:
16 #' \url{https://github.com/jashkenas/docco}
17 #' @export
18 #' @examples rocco_view=function(input) {
19 #' owd = setwd(tempdir()); on.exit(setwd(owd))
20 #' if (!file.exists(input)) return()
21 #' o=rocco(input, quiet=TRUE)
22 #' if (interactive()) browseURL(o)}
23 #' # knit these two vignettes using the docco style
24 #' rocco_view(system.file('doc', 'docco-classic.Rmd', package = 'knitr'))
25 #' rocco_view(system.file('doc', 'knit_expand.Rmd', package = 'knitr'))
26 rocco = function(input, ...) {
27 knit2html(
28 input, ...,
29 meta = list(
30 css = c('@npm/@xiee/utils/css/docco-classic.min.css', '@prism-xcode'),
31 js = c(
32 '@npm/[email protected]/dist/jquery.min.js',
33 '@npm/@xiee/utils/js/docco-classic.min.js,docco-resize.js',
34 '@npm/@xiee/utils/js/center-img.min.js'
35 )
36 )
37 )
38 }
39
40 # the Docco linear style
41 docco_linear = function(...) {
42 knit2html(..., meta = list(
43 css = c(
44 'https://ashkenas.com/docco/resources/linear/public/stylesheets/normalize.css',
45 'https://ashkenas.com/docco/resources/linear/docco.css', '@prism-xcode'
46 ),
47 js = '@npm/@xiee/utils/js/center-img.min.js',
48 `header-includes` = '<style type="text/css">.container{width:auto;max-width:920px;}.page{width:auto;max-width:800px;}.page pre{width:100%;max-width:768px;}pre, code{font-size:90%;}</style>',
49 `include-before` = '<div class="container"><div class="page">',
50 `include-after` = '<div class="fleur">h</div></div></div>'
51 ))
52 }