rstudio / markdown

The first generation of Markdown rendering for R (born in 2012), based on commonmark. Note that this package is markdown, not *rmarkdown*.
https://cran.r-project.org/package=markdown
Other
85 stars 78 forks source link

Detecting `html_format` from a document #121

Open dmurdoch opened 2 months ago

dmurdoch commented 2 months ago

Is there a way for a document to detect that it is being produced with output: markdown::html_format? I would like to use that output format for rgl vignettes, because then they will work even if Pandoc is not available. However, I need to distinguish HTML output from LaTeX output, because the former doesn't need PNG snapshots, whereas the latter does.

My previous test looked at knitr::pandoc_to(), but that doesn't appear to work with markdown::html_format when running R CMD build. It evaluates to a blank.

The logic I'm hoping for is something like this (a modified version of rgl:::knitrNeedsSnapshot):

knitrNeedsSnapshot <- function(options = knitr::opts_current$get()) {
  if (!is.null(options$snapshot))
    return(options$snapshot)
  if (isFALSE(options$screenshot.force))
    return(FALSE)
  force <- isTRUE(options$screenshot.force)
  if (isMarkdownHTMLformat())
    return(FALSE)
  fmt <- pandoc_to()
  if (!length(fmt) || force)
    return(TRUE)
  html_format <- fmt %in% c("html", "html4", "html5", "revealjs", 
                            "s5", "slideous", "slidy")
  !html_format
}

but so far I haven't got a reliable isMarkdownHTMLformat() function.

dmurdoch commented 2 months ago

Just noticed the related issue https://github.com/rstudio/markdown/issues/115, where I was assuming HTML would always be used.