diff --git a/src/library/tools/R/Rd2HTML.R b/src/library/tools/R/Rd2HTML.R index 7a068bae30c..c4635b8edfd 100644 --- a/src/library/tools/R/Rd2HTML.R +++ b/src/library/tools/R/Rd2HTML.R @@ -1376,18 +1376,15 @@ function(dir) ## License file pointers. ## ## For now only hyperlink for dynamic help. - ## Once httpd() knows about packageLicenseFileRegexp re <- "(.*[^[:space:]])?(([[:space:]]*\\+[[:space:]]*)?file )(LICEN[CS]E)" ind <- grepl(re, expansions) if(any(ind)) { y[ind] <- sub(re, - ## - ## packageLicenseFileRegexp - ## sprintf("\\2\\4", - ## p), - "\\2\\4", - ## + if(dynamic) { + sprintf("\\2\\4", + p) + } else "\\2\\4", expansions[ind]) expansions[ind] <- sub(re, "\\1", expansions[ind]) } @@ -1396,20 +1393,19 @@ function(dir) ## Components with labels in the R license db. ## For dynamic help, use the common licenses shipped with R ## instead of the R-project.org license URLs. - ## Once httpd() knows about commonLicenseFilesRegexp. ldb <- R_license_db() pos <- match(expansions, ldb$Labels) ind <- !is.na(pos) if(any(ind)) { pos <- pos[ind] - ## - ## commonLicenseFilesRegexp - ## paths <- ldb[pos, "File"] - ## urls <- ifelse(nzchar(paths), - ## sprintf("../../licenses/%s", basename(paths)), - ## ldb[pos, "URL"]) - urls <- ldb[pos, "URL"] - ## + urls <- if(dynamic) { + paths <- ldb[pos, "File"] + ifelse(nzchar(paths), + sprintf("/licenses/%s", + basename(paths)), + ldb[pos, "URL"]) + } else + urls <- ldb[pos, "URL"] texts <- if(expanded) { expansions[ind] } else { diff --git a/src/library/tools/R/dynamicHelp.R b/src/library/tools/R/dynamicHelp.R index f6d69a47f73..c632aa37b61 100644 --- a/src/library/tools/R/dynamicHelp.R +++ b/src/library/tools/R/dynamicHelp.R @@ -314,7 +314,7 @@ httpd <- function(path, query, ...) .HTML_package_description <- function(descfile) { pkg <- basename(dirname(descfile)) out <- c(HTMLheader(sprintf("Package ‘%s’", pkg)), - .DESCRIPTION_to_HTML(descfile), + .DESCRIPTION_to_HTML(descfile, dynamic = TRUE), "") list(payload = paste(out, collapse = "\n")) } @@ -376,6 +376,11 @@ httpd <- function(path, query, ...) formatted <- toHTML(news, title = "R News") return( list(payload = paste(formatted, collapse="\n")) ) } + else if(grepl("^/licenses/([^/.]*)$", path) && + file.exists(file <- file.path(R.home("share"), "licenses", + basename(path)))) + return(list(file = file, + "content-type" = "text/plain; charset=utf-8")) else if(!grepl("^/(doc|library|session)/", path)) return(error_page(paste("Only NEWS and URLs under", mono("/doc"), "and", mono("/library"), "are allowed"))) @@ -386,7 +391,6 @@ httpd <- function(path, query, ...) else if(path == "/doc/html/hsearch_db_keywords.html") return(.HTML_hsearch_db_keywords()) - ## ----------------------- per-package documentation --------------------- ## seems we got ../..// in the past fileRegexp <- "^/library/+([^/]*)/html/([^/]*)\\.html$" @@ -399,6 +403,8 @@ httpd <- function(path, query, ...) newsRegexp <- "^/library/([^/]*)/NEWS$" figureRegexp <- "^/library/([^/]*)/(help|html)/figures/([^/]*)$" sessionRegexp <- "^/session/" + packageIndexRegexp <- "^/library/([^/]*)$" + packageLicenseFileRegexp <- "^/library/([^/]*)/(LICEN[SC]E$)" file <- NULL if (grepl(topicRegexp, path)) { @@ -671,6 +677,22 @@ httpd <- function(path, query, ...) pkg <- sub(cssRegexp, "\\1", path) return( list(file = system.file("html", "R.css", package = pkg), "content-type" = "text/css") ) + } else if(grepl(packageIndexRegexp, path)) { + ## + ## Can we do this better? + url <- paste0(path, "/html/00Index.html") + return(list(payload = paste0('Redirect to "', + url, '"'), + "content-type" = 'text/html', + header = paste0('Location: ', url), + "status code" = 302L)) # temporary redirect + ## + } else if(grepl(packageLicenseFileRegexp, path) && + file.exists(file <- system.file(basename(path), + package = + basename(dirname(path))))) { + return(list(file = file, + "content-type" = "text/plain; charset=utf-8")) } else if (startsWith(path, "/library/")) { descRegexp <- "^/library/+([^/]+)/+DESCRIPTION$" if(grepl(descRegexp, path)) {