File: handlers.r

package info (click to toggle)
r-cran-irkernel 1.3.2%2Bgit20240429.124f234-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 242; javascript: 69; makefile: 26; sh: 15
file content (18 lines) | stat: -rw-r--r-- 800 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
prepare_mimebundle_kernel <- function(obj, handle_display_error = log_error) {
    # we always send text/plain, even if the user removed that from the option!
    text_bundle <- prepare_mimebundle(obj, 'text/plain', error_handler = handle_display_error)
    text_repr <- text_bundle$data[['text/plain']]
    
    # if the text/plain repr returns nothing, we also do
    if (is.null(text_repr) || nchar(text_repr) == 0L)
        return(list(data = NULL, metadata = NULL))
    
    if (getOption('jupyter.rich_display')) {
        mimetypes <- setdiff(getOption('jupyter.display_mimetypes'), 'text/plain')
        bundle <- prepare_mimebundle(obj, mimetypes, error_handler = handle_display_error)
        bundle$data[['text/plain']] <- text_repr
        bundle
    } else {
        text_bundle
    }
}