From 5cf5733fd72eea0d3bad5e4b503330bf8a115a88 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 21 Aug 2023 10:49:10 -0500 Subject: [PATCH] fix #103: mark the content in I() after reading the files, so that is_file() won't check if the strign is a file again also suppressWarnings() on file.exists() (this may be unneccesary but just to be conservative here) --- DESCRIPTION | 2 +- NEWS.md | 1 + R/utils.R | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d719c6c..c7210b9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: markdown Type: Package Title: Render Markdown with 'commonmark' -Version: 1.7.1 +Version: 1.7.2 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("JJ", "Allaire", role = "aut"), diff --git a/NEWS.md b/NEWS.md index e2b362f..06dfa80 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # CHANGES IN markdown VERSION 1.8 +- Fixed the superfluous warning about path lengths in `mark_html()` (thanks, @kenjisato, #103). # CHANGES IN markdown VERSION 1.7 diff --git a/R/utils.R b/R/utils.R index 0a9ca4f..26f4223 100644 --- a/R/utils.R +++ b/R/utils.R @@ -72,7 +72,7 @@ match_replace = function(x, pattern, replace = identity, ..., perl = TRUE) { # test if an input is a file path; if shouldn't be treated as file, use I() is_file = function(x) { - length(x) == 1 && !inherits(x, 'AsIs') && xfun::file_exists(x) + length(x) == 1 && !inherits(x, 'AsIs') && suppressWarnings(xfun::file_exists(x)) } # substitute a variable in template `x` with its value; the variable may have @@ -314,7 +314,7 @@ get_option = function(name, default = NULL) { one_string = function(x) { if (!is.character(x)) return('') if (is_file(x)) x = xfun::read_utf8(x) - paste(x, collapse = '\n') + I(paste(x, collapse = '\n')) } # find headings and build a table of contents as an unordered list @@ -725,7 +725,8 @@ resolve_files = function(x, ext = 'css') { ) x[i] = files[match(x[i], b)] x = c(x[i], x[!i]) - if (ext %in% c('css', 'js')) gen_tags(x, ext) else xfun::read_all(x) + x = if (ext %in% c('css', 'js')) gen_tags(x, ext) else xfun::read_all(x) + I(x) } # generate tags for css/js depending on whether they need to be embedded or offline