Author: Steffen Moeller <moeller@debian.org>
Description: Adding expressiveness in error message, also finding packages in system path.
Index: r-cran-rmarkdown/R/html_dependencies.R
===================================================================
--- r-cran-rmarkdown.orig/R/html_dependencies.R
+++ r-cran-rmarkdown/R/html_dependencies.R
@@ -239,11 +239,43 @@ validate_html_dependency <- function(lis
   if (is.null(list$src$file))
     stop("path for html_dependency not provided", call. = FALSE)
   file <- list$src$file
-  if (!is.null(list$package))
+  if (!is.null(list$package)) {
     file <- system.file(file, package = list$package)
-  if (!file.exists(file)) {
+    warning("validate_html_dependency: transformed package '",list$script,"' to file '",file)
+    list$src$file <- file
+  }
+
+  if (is.na(file) || "" == file) {
+    if (!is.null(list$script)) {
+       if (file.exists(paste(system.file(package="rmarkdown"),"rmd/h",list$script,sep="/"))) {
+          list$src$file <- paste(system.file(package="rmarkdown"),"rmd/h",sep="/")
+          return(list)
+       }
+       for(d in dir(paste(system.file(package="rmarkdown"),"rmd/h",sep="/"))) {
+          if (file.exists(paste(system.file(package="rmarkdown"),"rmd/h",d,list$script,sep="/"))) {
+             list$src$file <- paste(system.file(package="rmarkdown"),"rmd/h",d,sep="/")
+             return(list)
+          }
+       }
+       for(d in dir("/usr/share/javascript")) {
+          file <- paste("/usr/share/javascript",d,list$script,sep="/")
+          if (file.exists(file)) {
+             list$src$file <- d
+	     return(list)
+	  }
+       }
+       file <- paste(getwd(),list$script,sep="/")
+       warning("validate_html_dependency: transformed script '",list$script,"' to file '",file)
+       list$src$file <- getwd()
+    }
+  }
+
+  if (is.na(file) || "" == file) {
+    utils::str(list)
+    warning("validate_html_dependency was asked to search for a file dependency with no file name")
+  } else if (!file.exists(file)) {
     utils::str(list)
-    stop("path for html_dependency not found: ", file, call. = FALSE)
+    stop("path for html_dependency not found: '", file, "', expected in '", getwd(), "'", call. = FALSE)
   }
 
   list
