Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rstudio/rmarkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Nov 21, 2016
2 parents f211e9a + 40bb5c1 commit baa9c93
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
6 changes: 4 additions & 2 deletions R/pandoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,13 @@ pandoc_toc_args <- function(toc, toc_depth = 3) {
#' references)
#'
#' @param path Path to transform
#' @param backslash Whether to replace forward slashes in \code{path} with
#' backslashes on Windows
#'
#' @return Transformed path that can be passed to pandoc on the command line
#'
#' @export
pandoc_path_arg <- function(path) {
pandoc_path_arg <- function(path, backslash = TRUE) {

path <- path.expand(path)

Expand All @@ -306,7 +308,7 @@ pandoc_path_arg <- function(path) {
i <- grep(' ', path)
if (length(i))
path[i] <- utils::shortPathName(path[i])
path <- gsub('/', '\\\\', path)
if (backslash) path <- gsub('/', '\\\\', path)
}

path
Expand Down
6 changes: 4 additions & 2 deletions R/params.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
knit_params_get <- function(input_lines, params) {

# read the default parameters and extract them into a named list
knit_params <- mark_utf8(knitr::knit_params(input_lines))
knit_params <- knitr::knit_params(input_lines)
if (packageVersion('yaml') < '2.1.14') knit_params <- mark_utf8(knit_params)
default_params <- list()
for (param in knit_params) {
default_params[[param$name]] <- param$value
Expand Down Expand Up @@ -210,7 +211,8 @@ knit_params_ask <- function(file = NULL,
input_lines <- read_lines_utf8(file, encoding)
}

knit_params <- mark_utf8(knitr::knit_params(input_lines))
knit_params <- knitr::knit_params(input_lines)
if (packageVersion('yaml') < '2.1.14') knit_params <- mark_utf8(knit_params)

## Input validation on params (checks shared with render)
if (!is.null(params)) {
Expand Down
6 changes: 4 additions & 2 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,10 @@ render <- function(input,
if (!is.null(bibliography <- yaml_front_matter$bibliography)) {
# remove the .bib extension since it does not work with MikTeX's BibTeX
if (need_bibtex && is_windows()) bibliography <- sub('[.]bib$', '', bibliography)
output_format$pandoc$args <- c(output_format$pandoc$args,
rbind("--bibliography", pandoc_path_arg(bibliography)))
output_format$pandoc$args <- c(
output_format$pandoc$args,
rbind("--bibliography", pandoc_path_arg(bibliography, FALSE))
)
}

# add an id-prefix if this is runtime: shiny
Expand Down
10 changes: 8 additions & 2 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ mark_utf8 <- function(x) {
res
}

# TODO: remove this when fixed upstream https://github.com/viking/r-yaml/issues/6
# the yaml UTF-8 bug has been fixed https://github.com/viking/r-yaml/issues/6
# but yaml >= 2.1.14 Win/Mac binaries are not available for R < 3.2.0, so we
# still need the mark_utf8 trick
yaml_load_utf8 <- function(string, ...) {
string <- paste(string, collapse = '\n')
mark_utf8(yaml::yaml.load(enc2utf8(string), ...))
if (packageVersion('yaml') >= '2.1.14') {
yaml::yaml.load(string, ...)
} else {
mark_utf8(yaml::yaml.load(enc2utf8(string), ...))
}
}

yaml_load_file_utf8 <- function(input, ...) {
Expand Down
2 changes: 2 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ rmarkdown 1.2

* Improve alignment of text in sub-topics for floating TOC

* Bibliography file paths in YAML containing forward slashes could not be
rendered (#875)

rmarkdown 1.1
--------------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion man/pandoc_path_arg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit baa9c93

Please sign in to comment.