Skip to content

Commit

Permalink
Fix help on Windows (#224)
Browse files Browse the repository at this point in the history
* Fix Windows error caused by invalid path chars
* Prevent warning when displaying HTML help
* Make code more readable
* Ignore generated DLL files
* Document changes
  • Loading branch information
klmr committed Jul 30, 2021
1 parent 380d0b8 commit dd09a26
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
/pkgdown/favicon/
/src/*.o
/src/*.so
/src/*.dll
/vignettes/*.html
/vignettes/*.R
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# box (development version)

* Fix: make interactive HTML module help work on Windows (#223)
* Fix: prevent segfault in R ≤ 3.6.1 caused by missing declaration of internal R
symbol (#213)
* Fix: Allow exporting modules that were previously imported using a different
Expand Down
17 changes: 10 additions & 7 deletions R/display-help.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compile_help.text_help_format = function (x, rd) {
}

compile_help.html_help_format = function (x, rd) {
tools::Rd2HTML(rd, out = tempfile('Rtxt'), package = mock_package_name)
tools::Rd2HTML(rd, out = tempfile('Rtxt'), package = c(mock_package_name, NA_character_))
}

patch_topic_name.text_help_format = function (x, file, topic) {
Expand All @@ -28,21 +28,24 @@ patch_topic_name.text_help_format = function (x, file, topic) {
}

patch_topic_name.html_help_format = function (x, file, topic) {
topic = gsub('"', '"',
gsub('<', '&gt;',
gsub('<', '&lt;',
gsub('&', '&amp;', topic))))
from = c('&', '<', '>', '"')
to = c('&amp;', '&lt;', '&gt;', '&quot;')
replace = data.frame(rbind(from, to))
topic = Reduce(function (x, r) gsub(r[1L], r[2L], x), replace, topic)
doc_text = readLines(file)
doc_text = gsub(mock_package_name, topic, doc_text)
writeLines(doc_text, file)
}

display_help_file.text_help_format = function (x, file, topic) {
file.show(file, title = gettextf('R Help on %s', dQuote(topic)),
delete.file = TRUE)
file.show(
file, title = gettextf('R Help on %s', dQuote(topic)),
delete.file = TRUE
)
}

display_help_file.html_help_format = function (x, file, topic) {
topic = sanitize_path(topic)
port = tools::startDynamicHelp(NA)
html_path = file.path(tempdir(), sprintf('.R/doc/html/%s.html', topic))
dir.create(dirname(html_path), recursive = TRUE, showWarnings = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/help.r
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ help = function (topic, help_type = getOption('help_type', 'text')) {
}
}

display_help(doc, paste0('module:', mod_name), help_type)
display_help(doc, mod_name, help_type)
}

#' Parse a module’s documentation
Expand Down
8 changes: 8 additions & 0 deletions R/paths.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ split_path = function (path) {
merge_path = function (components) {
do.call('file.path', as.list(components))
}

#' \code{sanitize_path(path)} replaces invalid characters in the given
#' \emph{relative} path, making the result a valid Windows path.
#' @rdname paths
sanitize_path = function (path) {
win32_reserved_path_chars = '[<>:"/\\|?*]'
gsub(win32_reserved_path_chars, '_', path)
}

0 comments on commit dd09a26

Please sign in to comment.