Skip to content

htmlDependency() sometimes doesn't allow list entries for script #320

@dmurdoch

Description

@dmurdoch

The script component of htmlDependency can be a list containing list entries in order to set attributes on the included script. However, if all_files = FALSE is used, this fails. For example, the markdown file below fails to render. Changing all_files to TRUE makes it work, as does changing self_contained to true.

The problem appears to be here:

unlist(dependency[c('script', 'stylesheet', 'attachment')])

because the code assumes dependencies are all simple filenames.

Here's the sample file to demonstrate:

---
title: "Untitled"
output: 
  html_document:
    self_contained: false
---

```{r}
javascript <- 'console.log("this is Javascript to write to the console");'
f1 <- tempfile(fileext = ".js")
writeLines(javascript, f1)

text <- 'this is some text to go in a script'
f2 <- tempfile(fileext = ".txt")
writeLines(text, f2)
```

```{r}
library(htmltools)
deps <- htmlDependency("test", "1.0",
                       src = tempdir(),
                       script = list(basename(f1),
                                     list(src = basename(f2),
                                          type = "text/plain",
                                          id = "shader")),
                       all_files = FALSE
                       )
tag <- tags$p("this is visible text", deps)
tag
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions