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

How to call markdown::mark_html() without seeing maximum path length warning? #103

Closed
kenjisato opened this issue Aug 21, 2023 · 5 comments
Assignees
Labels

Comments

@kenjisato
Copy link

On my Mac, a warning message is issued with the following minimal call to markdown::mark_html().

. <- markdown::mark_html("hello")
#> Warning in file.info(x, extra_cols = FALSE): expanded path length 1663 would be too long for
#> <style type="text/css">
#> body {
#>   font-family: sans-s [... truncated]

Created on 2023-08-21 with reprex v2.0.2

This warning appears because xfun::file_exists(), or ultimately file.info(), is attempted against the content of the CSS file. With default.css, this warning may only appear on Mac, where the maximum path length is 1023. With a larger CSS file, the same warning could appear on other platforms, I suppose.

After some struggles, I noticed that this warning shows up only when the meta$css is given as an absolute path.

oopts <- options()
options(warning.length = 100)

# Copy the default CSS to simulate custom CSS
dir.create(tdir <- tempfile(pattern = "dir", tmpdir = "."))
. <- file.copy(system.file("resources/default.css", package = "markdown"), tdir)
(custom_css <- file.path(tdir, "default.css"))
#> [1] "./dir7b19758ba261/default.css"

# No warning with a relative path
relative <-
  markdown::mark_html("hello", meta = list(css = custom_css))

# Warning appears for an absolute path
absolute <-
  markdown::mark_html("hello", meta = list(css = normalizePath(custom_css)))
#> Warning in file.info(x, extra_cols = FALSE): expanded path length 1663 would be too long for
#> <style type="text/css">
#> body {
#>   font-family: sans-s [... truncated]

unlink(tdir, recursive = TRUE)
options(oopts)

Created on 2023-08-21 with reprex v2.0.2

My intention is to write a package that calls markdown::mark() with a custom CSS, which will be passed with a system.file()-generated absolute path. It would be great if there is a clean way to avoid the file.info() warning. (i.e., cleaner than using suppressWarnings() I mean...)

Would you have any recommendations? Thanks!

@yihui yihui moved this to Todo In Progress in R Markdown Team Projects Aug 21, 2023
@yihui yihui added the bug label Aug 21, 2023
@yihui yihui closed this as completed in 5cf5733 Aug 21, 2023
@github-project-automation github-project-automation bot moved this from Todo In Progress to Done in R Markdown Team Projects Aug 21, 2023
@yihui
Copy link
Member

yihui commented Aug 21, 2023

Should be fixed now. Thanks for the report!

@yihui yihui self-assigned this Aug 21, 2023
@kenjisato
Copy link
Author

Great. Thanks!

@yihui
Copy link
Member

yihui commented Aug 21, 2023

You are welcome! You can test it with

install.packages('markdown', repos = c('https://rstudio.r-universe.dev', 'https://cloud.r-project.org'))

@kenjisato
Copy link
Author

Confirmed that it is working!

@yihui
Copy link
Member

yihui commented Aug 22, 2023

Great. I'll make a new release tomorrow. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants