1+ # Most (if not all) from github.com/rstudio/rmarkdown
2+
3+ from_rmarkdown <- function (implicit_figures = TRUE , extensions = NULL ) {
4+ extensions <- paste0(extensions , collapse = " " )
5+ extensions <- gsub(" " , " " , extensions )
6+ if (! implicit_figures && ! grepl(" implicit_figures" , extensions ))
7+ extensions <- paste0(" -implicit_figures" , extensions )
8+ rmarkdown_format(extensions )
9+ }
10+
11+ from_rst <- function (extensions = NULL ) {
12+ format <- c(" rst" )
13+ addExtension <- function (extension ) {
14+ if (length(grep(extension , extensions )) == 0 )
15+ format <<- c(format , paste0(" +" , extension ))
16+ }
17+ addExtension(" autolink_bare_uris" )
18+ addExtension(" ascii_identifiers" )
19+ addExtension(" tex_math_single_backslash" )
20+ format <- c(format , extensions , recursive = TRUE )
21+ paste(format , collapse = " " )
22+ }
23+
24+ pandoc_html_highlight_args <- function (highlight , template , self_contained ,
25+ files_dir , output_dir ) {
26+ args <- c()
27+ if (is.null(highlight )) {
28+ args <- c(args , " --no-highlight" )
29+ }
30+ else if (! identical(template , " default" )) {
31+ if (identical(highlight , " default" ))
32+ highlight <- " pygments"
33+ args <- c(args , " --highlight-style" , highlight )
34+ }
35+ else {
36+ highlight <- match.arg(highlight , html_highlighters())
37+ if (highlight %in% c(" default" , " textmate" )) {
38+ highlight_path <- system.file(" rmd/h/highlight" , package = " rmarkdown" )
39+ if (self_contained )
40+ highlight_path <- pandoc_path_arg(highlight_path )
41+ else {
42+ highlight_path <- normalized_relative_to(output_dir ,
43+ render_supporting_files(highlight_path , files_dir ))
44+ }
45+ args <- c(args , " --no-highlight" )
46+ args <- c(args , " --variable" , paste(" highlightjs=" ,
47+ highlight_path , sep = " " ))
48+ if (identical(highlight , " textmate" )) {
49+ args <- c(args , " --variable" , paste(" highlightjs-theme=" ,
50+ highlight , sep = " " ))
51+ }
52+ }
53+ else {
54+ args <- c(args , " --highlight-style" , highlight )
55+ }
56+ }
57+ args
58+
59+ }
60+
61+ html_highlighters <- function () { c(highlighters(), " textmate" ) }
62+ highlighters <- function () {
63+ c(" default" , " tango" , " pygments" , " kate" , " monochrome" , " espresso" ,
64+ " zenburn" , " haddock" )
65+ }
66+
67+ normalized_relative_to <- function (dir , file ) {
68+ relative_to(normalizePath(dir , winslash = " /" , mustWork = FALSE ),
69+ normalizePath(file , winslash = " /" , mustWork = FALSE ))
70+ }
71+
72+ normalize_path <- function (path ) {
73+ if (is.null(path ))
74+ NULL
75+ else normalizePath(path , winslash = " /" , mustWork = FALSE )
76+ }
0 commit comments