Skip to content

Commit

Permalink
better detection of Rmd v2 input in knit2html(), so it no longer warn…
Browse files Browse the repository at this point in the history
…s against documents that use markdown:: or litedown:: output formats
  • Loading branch information
yihui committed Apr 3, 2024
1 parent 427cf6c commit 6d48fec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/utils-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ knit2html = function(
if (is_cran_check() && !has_package('markdown'))
return(vweave_empty(input, .reason = 'markdown'))

if (!force_v1 && is.null(text)) {
if (length(grep('^---\\s*$', head(read_utf8(input), 1)))) warning2(
if (!force_v1 && is.null(text) && is_rmd_v2(input)) {
warning2(
'It seems you should call rmarkdown::render() instead of knitr::knit2html() ',
'because ', input, ' appears to be an R Markdown v2 document.'
)
Expand All @@ -173,6 +173,13 @@ knit2html = function(
} else markdown::mark_html(text = out, ...)
}

# test if an Rmd input should be rendered via rmarkdown::render() or (mark|lite)down::mark()
is_rmd_v2 = function(input, text = read_utf8(input)) {
res = xfun::yaml_body(text)$yaml[['output']]
if (is.list(res)) res = names(res)
length(res) > 0 && is.character(res) && !any(grepl('(mark|lite)down::', res))
}

#' Knit an R Markdown document and post it to WordPress
#'
#' This function is a wrapper around the \pkg{RWordPress} package. It compiles
Expand Down

0 comments on commit 6d48fec

Please sign in to comment.