Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--highlight-style argument does not accept a shortpath name on WINDOWS #1976

Closed
cderv opened this issue Dec 9, 2020 · 3 comments
Closed
Labels
bug an unexpected problem or unintended behavior theme: pandoc concerns upstream pandoc

Comments

@cderv
Copy link
Collaborator

cderv commented Dec 9, 2020

I isolated the bug to be with Windows and shortpath name transformation when there is a space in the path: It seems --highlight-style does not handle it.

Reprex

dummy proj for the example

dir.create(tmp_dir <- tempfile(tmpdir = "."))
owd <- setwd(tmp_dir)

create a dummy md file

xfun::write_utf8(c(
  "# A header"
), "test.md")

Get the distill theme file for example

packageVersion("distill")
#> [1] '1.1'
theme_file <- distill:::distill_resource("arrow.theme")

create a copy in a directory with space

dir.create(theme_dir <- "dir with space")
file.copy(theme_file, theme_dir)
#> [1] TRUE
theme_file_copy <- file.path(theme_dir, basename(theme_file))

helper function

convert <- function(theme) {
  rmarkdown::pandoc_convert("test.md", to = 'html', output = "test.html",
                            options = c("--highlight-style", theme),
                            verbose = TRUE)
}

With a path without space no issue

convert(theme_file)
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --highlight-style "C:/Users/chris/Documents/R/win-library/4.0/distill/rmarkdown/templates/distill_article/resources/arrow.theme"
convert(rmarkdown::pandoc_path_arg(theme_file))
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --highlight-style "C:\Users\chris\Documents\R\win-library\4.0\distill\rmarkdown\templates\distill_article\resources\arrow.theme"

With a space in name, it is working well

convert(theme_file_copy)
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --highlight-style "dir with space/arrow.theme"

unless path is modified by rmarkdown::pandoc_path_arg()

convert(rmarkdown::pandoc_path_arg(theme_file_copy))
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --highlight-style "DIRWIT~1\ARROW~1.THE"
Unknown highlight-style DIRWIT~1\ARROW~1.THE
#> Error: pandoc document conversion failed with error 6

which use utils::shortPathName - this is cause the issue

convert(utils::shortPathName(theme_file_copy))
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --highlight-style "DIRWIT~1\ARROW~1.THE"
Unknown highlight-style DIRWIT~1\ARROW~1.THE
#> Error: pandoc document conversion failed with error 6

Clean

setwd(owd)
unlink(tmp_dir, recursive = TRUE)

Created on 2020-12-09 by the reprex package (v0.3.0.9001)

If a fix is to be made in our tool, this would be in rmarkdown not distill. I'll report upstream because it seems it is not causing any issue with other argument

# dummy proj for the example
dir.create(tmp_dir <- tempfile(tmpdir = "."))
owd <- setwd(tmp_dir)
# create a dummy md file
xfun::write_utf8(c(
  "---",
  "title: test",
  "---",
  "# A header"
), "test.md")

# create a copy in a directory with space 
dir.create(sub_dir <- "dir with space")
template_file <- file.path(sub_dir, "template.html")
xfun::write_utf8(c(
  "$body$"
), template_file)

# helper function
convert <- function(template) {
  rmarkdown::pandoc_convert("test.md", to = 'html', output = "test.html",
                            options = c("--template", template),
                            verbose = TRUE)
}

# No issues
convert(template_file)
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --template "dir with space/template.html"
convert(rmarkdown::pandoc_path_arg(template_file))
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --template "DIRWIT~1\TEMPLA~1.HTM"
convert(utils::shortPathName(template_file))
#> "C:/Users/chris/scoop/apps/rstudio-daily/current/bin/pandoc/pandoc" +RTS -K512m -RTS test.md --to html4 --output test.html --template "DIRWIT~1\TEMPLA~1.HTM"
# Clean
setwd(owd)
unlink(tmp_dir, recursive = TRUE)

Let's precise that it seems Pandoc on Windows no how to handle space in path, so maybe utils::shortPathName is nor more required.

Originally posted by @cderv in rstudio/distill#214 (comment)

@cderv cderv added bug an unexpected problem or unintended behavior theme: pandoc concerns upstream pandoc labels Dec 9, 2020
@cderv
Copy link
Collaborator Author

cderv commented Dec 9, 2020

So we got the reply in jgm/pandoc#6939:

--highlight-style knows that a FILE has been provided looking at the extension which is expected to be .theme. Short Path Name transformation will result in an .THM extension.

It was also confirmed that file path enclosed in double quotes with space are mostly ok for Pandoc. I don't really know from which version.

Several solutions here:

  1. Don't use pandoc_path_arg for --highlight-style : as seen above it works fine.
  2. Only use utils::shortPathName() on dirname(), and not the file itself (which will usually not contain space)
  3. Remove completely utils::shortPathName() on Windows in pandoc_path_arg()

cderv added a commit to cderv/distill that referenced this issue Dec 9, 2020
cderv added a commit to cderv/distill that referenced this issue Dec 9, 2020
cderv added a commit to cderv/distill that referenced this issue Dec 9, 2020
cderv added a commit that referenced this issue Dec 9, 2020
@cderv
Copy link
Collaborator Author

cderv commented Dec 9, 2020

In fact this is handle correctly in rmarkdown as currently, it can't take a theme file but the PR #1881 which offer support for that correctly do not use pandoc_path_arg. So solution 1 from above.

@cderv cderv closed this as completed Dec 9, 2020
@github-actions
Copy link

github-actions bot commented Jun 8, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior theme: pandoc concerns upstream pandoc
Projects
None yet
Development

No branches or pull requests

1 participant