From 1e16b43faef911ca42134455a39ce06129676b30 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Thu, 12 Oct 2023 20:25:52 +0200 Subject: [PATCH 01/11] Make pkgdown work for collapse. --- R/rd.R | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/R/rd.R b/R/rd.R index 91d03c1c0..9ad402727 100644 --- a/R/rd.R +++ b/R/rd.R @@ -2,18 +2,32 @@ rd_text <- function(x, fragment = TRUE) { con <- textConnection(x) on.exit(close(con), add = TRUE) - set_classes(tools::parse_Rd(con, fragment = fragment, encoding = "UTF-8")) + set_classes(parse_Rd2(con, fragment = fragment, encoding = "UTF-8")) +} + +parse_Rd2 <- function(file, ...) { + substcr <- function(x) gsub("\\cr\\cr", "\\cr", gsub("\\cr \\cr", "\\cr", x, fixed = TRUE), fixed = TRUE) + lines <- read_lines(file) + if(endsWith(file, "collapse-options.Rd")) { + lines <- gsub("\\tab\\tab", "\\tab", gsub("\\tab \\tab", "\\tab", lines, fixed = TRUE), fixed = TRUE) + lines <- gsub("\\tabular{lll}", "\\tabular{ll}", lines, fixed = TRUE) + } + tmp <- tempfile(fileext = ".Rd") + write_lines(substcr(substcr(substcr(substcr(substcr(lines))))), tmp) + res <- tools::parse_Rd(tmp, ...) + file.remove(tmp) + res } rd_file <- function(path, pkg_path = NULL) { if (getRversion() >= "3.4.0") { macros <- tools::loadPkgRdMacros(pkg_path) - set_classes(tools::parse_Rd(path, macros = macros, encoding = "UTF-8")) + set_classes(parse_Rd2(path, macros = macros, encoding = "UTF-8")) } else if (getRversion() >= "3.2.0") { macros <- tools::loadPkgRdMacros(pkg_path, TRUE) - set_classes(tools::parse_Rd(path, macros = macros, encoding = "UTF-8")) + set_classes(parse_Rd2(path, macros = macros, encoding = "UTF-8")) } else { - set_classes(tools::parse_Rd(path, encoding = "UTF-8")) + set_classes(parse_Rd2(path, encoding = "UTF-8")) } } From 738482e7df45644c0baa3ff62bf9f45e2f7f0c2f Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Fri, 13 Oct 2023 00:05:37 +0200 Subject: [PATCH 02/11] Always showing badges + removing download badges. --- R/build-home-index.R | 2 +- R/tweak-homepage.R | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/build-home-index.R b/R/build-home-index.R index 3c39aca2a..4f86fe615 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -22,7 +22,7 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { render_page(pkg, "home", data, "index.html", quiet = quiet) strip_header <- isTRUE(pkg$meta$home$strip_header) - hide_badges <- pkg$development$mode == "release" && !pkg$development$in_dev + hide_badges <- FALSE # pkg$development$mode == "release" && !pkg$development$in_dev update_html( dst_path, diff --git a/R/tweak-homepage.R b/R/tweak-homepage.R index b1a77797a..ac177df5c 100644 --- a/R/tweak-homepage.R +++ b/R/tweak-homepage.R @@ -115,7 +115,8 @@ badges_extract <- function(html) { xml2::xml_remove(x) - as.character(badges) + badges <- as.character(badges) + badges[!grepl("download", badges, ignore.case = TRUE)] } badges_extract_text <- function(x) { From 46910a1bc381cafa6421488ffcc61ef75e8d4dcf Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Fri, 13 Oct 2023 17:07:00 +0200 Subject: [PATCH 03/11] Improving function reference index rendering: removing aliases and shorthands for cleaner presentation. --- R/build-reference-index.R | 9 ++++++++- R/rd.R | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/R/build-reference-index.R b/R/build-reference-index.R index d8e4df7e5..aed87fe87 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -1,6 +1,13 @@ data_reference_index <- function(pkg = ".") { pkg <- as_pkgdown(pkg) + # This removes shorthands from reference index + sh <- getNamespace("collapse")[[".SHORTHANDS"]] + sh <- sh[!endsWith(sh, "<-")] + sh <- c(sh, paste0("`", sh), ".quantile", ".range", "`[", "`$") + pkg$topics$funs <- lapply(pkg$topics$funs, function(y) if(length(y)) + y[rowSums(do.call(cbind, lapply(sh, startsWith, x = y))) <= 0] else y) + meta <- pkg$meta[["reference"]] %||% default_reference_index(pkg) if (length(meta) == 0) { return(list()) @@ -17,7 +24,7 @@ data_reference_index <- function(pkg = ".") { rows <- Filter(function(x) !x$is_internal, rows) print_yaml(list( - pagetitle = tr_("Function reference"), + pagetitle = tr_("Function Reference"), rows = rows, has_icons = has_icons )) diff --git a/R/rd.R b/R/rd.R index 9ad402727..63a332167 100644 --- a/R/rd.R +++ b/R/rd.R @@ -12,6 +12,16 @@ parse_Rd2 <- function(file, ...) { lines <- gsub("\\tab\\tab", "\\tab", gsub("\\tab \\tab", "\\tab", lines, fixed = TRUE), fixed = TRUE) lines <- gsub("\\tabular{lll}", "\\tabular{ll}", lines, fixed = TRUE) } + clpns <- getNamespace("collapse") + nam <- names(clpns) + rm_alias <- c(clpns[[".SHORTHANDS"]], + setdiff(nam[startsWith(nam, ".")], c(".", ".c")), + nam[startsWith(nam, "[")], + nam[startsWith(nam, "$")]) + rm_alias <- paste0("\\alias{", rm_alias) + lines <- lines[!startsWith(lines, "%")] + lines <- lines[!startsWith(lines, "\\alias{A")] + lines <- lines[rowSums(sapply(rm_alias, startsWith, x = lines, USE.NAMES = FALSE)) <= 0] tmp <- tempfile(fileext = ".Rd") write_lines(substcr(substcr(substcr(substcr(substcr(lines))))), tmp) res <- tools::parse_Rd(tmp, ...) From 77ed3e1515b801df3a1d856d1568470036acbece Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sat, 1 Jun 2024 11:27:39 +0200 Subject: [PATCH 04/11] Disable narrow spacing again. --- inst/BS5/assets/pkgdown.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/BS5/assets/pkgdown.scss b/inst/BS5/assets/pkgdown.scss index f3431521b..ea2afaafb 100644 --- a/inst/BS5/assets/pkgdown.scss +++ b/inst/BS5/assets/pkgdown.scss @@ -246,8 +246,8 @@ body { // spacing tweaks // Use an indent for defintions rather than horitzonal space -dl {margin-bottom: 0;} -dd {padding-left: 1.5rem; margin-bottom: 0.25rem} +// dl {margin-bottom: 0;} +dd {padding-left: 1.5rem} // margin-bottom: 0.25rem} // Use margins rather than size to distinguish headings h2, .h2 { font-size: 1.75rem; margin-top: 1.5rem;} From 5325213137129e6055a2c70ce4c493f5e85e2434 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 00:27:47 +0200 Subject: [PATCH 05/11] Support syntax highlighting for subset/assignment methods. --- R/highlight.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/highlight.R b/R/highlight.R index 05a4e0a8e..d0fec4f0b 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -1,7 +1,13 @@ # highligh_text() and highlight_examples() are only used for usage # and examples, and are specifically excluded in tweak_reference_highlighting() highlight_text <- function(text) { + text <- gsub("[[(", "`[[`(", text, fixed = TRUE) + text <- gsub("[(", "`[`(", text, fixed = TRUE) + text <- gsub("$(", "`$`(", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) + out <- gsub("`[[`(", "[[(", out, fixed = TRUE) + out <- gsub("`[`(", "[(", out, fixed = TRUE) + out <- gsub("`$`(", "$(", out, fixed = TRUE) if (!is.na(out)) { sourceCode(pre(out, r_code = TRUE)) } else { From fb5aace6ffb31acc934b8447c190e96e849c66c8 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 00:32:18 +0200 Subject: [PATCH 06/11] Better. --- R/highlight.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/highlight.R b/R/highlight.R index d0fec4f0b..626336b1f 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -5,9 +5,9 @@ highlight_text <- function(text) { text <- gsub("[(", "`[`(", text, fixed = TRUE) text <- gsub("$(", "`$`(", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) - out <- gsub("`[[`(", "[[(", out, fixed = TRUE) - out <- gsub("`[`(", "[(", out, fixed = TRUE) - out <- gsub("`$`(", "$(", out, fixed = TRUE) + out <- gsub("`[[`", "[[", out, fixed = TRUE) + out <- gsub("`[`", "[", out, fixed = TRUE) + out <- gsub("`$`", "$", out, fixed = TRUE) if (!is.na(out)) { sourceCode(pre(out, r_code = TRUE)) } else { From 1081f7b341bfea7015e63560a998dbebc7c023b2 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 01:44:46 +0200 Subject: [PATCH 07/11] Keep functional notation. --- R/highlight.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/highlight.R b/R/highlight.R index 626336b1f..bcb528c27 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -5,9 +5,9 @@ highlight_text <- function(text) { text <- gsub("[(", "`[`(", text, fixed = TRUE) text <- gsub("$(", "`$`(", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) - out <- gsub("`[[`", "[[", out, fixed = TRUE) - out <- gsub("`[`", "[", out, fixed = TRUE) - out <- gsub("`$`", "$", out, fixed = TRUE) + # out <- gsub("`[[`", "[[", out, fixed = TRUE) + # out <- gsub("`[`", "[", out, fixed = TRUE) + # out <- gsub("`$`", "$", out, fixed = TRUE) if (!is.na(out)) { sourceCode(pre(out, r_code = TRUE)) } else { From 698a5b8856e97f6c01cfc1265253f16dd281ebb0 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 01:56:29 +0200 Subject: [PATCH 08/11] Highlight template code for optional arguments. --- R/highlight.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/highlight.R b/R/highlight.R index bcb528c27..07f9dbd7c 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -4,6 +4,11 @@ highlight_text <- function(text) { text <- gsub("[[(", "`[[`(", text, fixed = TRUE) text <- gsub("[(", "`[`(", text, fixed = TRUE) text <- gsub("$(", "`$`(", text, fixed = TRUE) + # For fast-statistical-functions.Rd + text <- gsub(", [w = NULL,]", ", w = NULL,", text, fixed = TRUE) + text <- gsub(", [na.rm = TRUE,]", ", na.rm = TRUE,", text, fixed = TRUE) + text <- gsub(", [nthreads = 1L,]", ", nthreads = 1L,", text, fixed = TRUE) + text <- gsub("[keep.w = TRUE,] [stub = TRUE,] [nthreads = 1L,]", "keep.w = TRUE, stub = TRUE, nthreads = 1L,", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) # out <- gsub("`[[`", "[[", out, fixed = TRUE) # out <- gsub("`[`", "[", out, fixed = TRUE) From 3bd62d193c50e6fedeb27a230ed6e230960b8a26 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 02:11:05 +0200 Subject: [PATCH 09/11] Change order. --- R/highlight.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/highlight.R b/R/highlight.R index 07f9dbd7c..597a4d97e 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -5,10 +5,10 @@ highlight_text <- function(text) { text <- gsub("[(", "`[`(", text, fixed = TRUE) text <- gsub("$(", "`$`(", text, fixed = TRUE) # For fast-statistical-functions.Rd + text <- gsub("[keep.w = TRUE,] [stub = TRUE,] [nthreads = 1L,]", "keep.w = TRUE, stub = TRUE, nthreads = 1L,", text, fixed = TRUE) text <- gsub(", [w = NULL,]", ", w = NULL,", text, fixed = TRUE) text <- gsub(", [na.rm = TRUE,]", ", na.rm = TRUE,", text, fixed = TRUE) text <- gsub(", [nthreads = 1L,]", ", nthreads = 1L,", text, fixed = TRUE) - text <- gsub("[keep.w = TRUE,] [stub = TRUE,] [nthreads = 1L,]", "keep.w = TRUE, stub = TRUE, nthreads = 1L,", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) # out <- gsub("`[[`", "[[", out, fixed = TRUE) # out <- gsub("`[`", "[", out, fixed = TRUE) From 26a4da0c3c800e6cde7b2ec533157bf17a2ff7ce Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 2 Jun 2024 02:15:55 +0200 Subject: [PATCH 10/11] Remove renamed links. --- R/rd.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/rd.R b/R/rd.R index 63a332167..85376a4d0 100644 --- a/R/rd.R +++ b/R/rd.R @@ -21,6 +21,9 @@ parse_Rd2 <- function(file, ...) { rm_alias <- paste0("\\alias{", rm_alias) lines <- lines[!startsWith(lines, "%")] lines <- lines[!startsWith(lines, "\\alias{A")] + lines <- lines[!startsWith(lines, "\\alias{fN")] + lines <- lines[!startsWith(lines, "\\alias{pwN")] + lines <- lines[!startsWith(lines, "\\alias{fHD")] lines <- lines[rowSums(sapply(rm_alias, startsWith, x = lines, USE.NAMES = FALSE)) <= 0] tmp <- tempfile(fileext = ".Rd") write_lines(substcr(substcr(substcr(substcr(substcr(lines))))), tmp) From 329fed9ebac79fb18527ca6846239294e8512f4c Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Tue, 4 Jun 2024 00:39:42 +0200 Subject: [PATCH 11/11] Remove all changes to highlight again. --- R/highlight.R | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/R/highlight.R b/R/highlight.R index 597a4d97e..05a4e0a8e 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -1,18 +1,7 @@ # highligh_text() and highlight_examples() are only used for usage # and examples, and are specifically excluded in tweak_reference_highlighting() highlight_text <- function(text) { - text <- gsub("[[(", "`[[`(", text, fixed = TRUE) - text <- gsub("[(", "`[`(", text, fixed = TRUE) - text <- gsub("$(", "`$`(", text, fixed = TRUE) - # For fast-statistical-functions.Rd - text <- gsub("[keep.w = TRUE,] [stub = TRUE,] [nthreads = 1L,]", "keep.w = TRUE, stub = TRUE, nthreads = 1L,", text, fixed = TRUE) - text <- gsub(", [w = NULL,]", ", w = NULL,", text, fixed = TRUE) - text <- gsub(", [na.rm = TRUE,]", ", na.rm = TRUE,", text, fixed = TRUE) - text <- gsub(", [nthreads = 1L,]", ", nthreads = 1L,", text, fixed = TRUE) out <- downlit::highlight(text, classes = downlit::classes_pandoc()) - # out <- gsub("`[[`", "[[", out, fixed = TRUE) - # out <- gsub("`[`", "[", out, fixed = TRUE) - # out <- gsub("`$`", "$", out, fixed = TRUE) if (!is.na(out)) { sourceCode(pre(out, r_code = TRUE)) } else {