-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Printing in Jupyter notebook #8
Comments
This is an issue in the repr package, which circumvents dispatching |
Implement and export |
Initial implementation: # repr/R/utils.r:
html_escape <- local({
html_specials <- c(
`&` = "&",
`<` = "<",
`>` = ">"
)
pre_wrap <- "<span style=white-space:pre-wrap>%s</span>"
function(text) {
for (chr in names(html_specials))
text <- gsub(chr, html_specials[[chr]], text, fixed = TRUE)
consec_spaces <- grepl("\ \ ", text)
text[consec_spaces] <- sprintf(pre_wrap, text[consec_spaces])
text
}
})
#' @importFrom utils capture.output
as_repr_html <- function(class) {
printer <- get(paste0("print.", class))
wrap <- "<pre class=language-r><code>%s</code></pre>"
function(obj, ...) {
code <- capture.output(printer(obj))
sprintf(wrap, paste(html_escape(code), collapse = "\n"))
}
}
#' @importFrom repr repr_html
NULL
#' @export
repr_html.CompositeFunction <- as_repr_html("CompositeFunction")
#' @export
repr_html.PartialFunction <- as_repr_html("PartialFunction") |
Enable option to syntax-highlight. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Executing a cell like
ignores the class and prints
whereas
applies the correct print method
Similar problem occurs for other custom gestalt classes (
"PartialFunction"
, etc.).Is this an issue with Jupyter and/or gestalt?
The text was updated successfully, but these errors were encountered: