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

Detecting html_format from a document #121

Open
dmurdoch opened this issue Jul 6, 2024 · 1 comment
Open

Detecting html_format from a document #121

dmurdoch opened this issue Jul 6, 2024 · 1 comment

Comments

@dmurdoch
Copy link
Contributor

dmurdoch commented Jul 6, 2024

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
Copy link
Contributor Author

dmurdoch commented Jul 8, 2024

Just noticed the related issue #115, where I was assuming HTML would always be used.

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

No branches or pull requests

1 participant