From 93a4a8578ad47b58cf76f753bc229326b94a137c Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Tue, 28 Jun 2016 17:31:20 +0200 Subject: [PATCH] Isolate full html pages This is similar how the IRkernel does it if it encounters a complete html page. --- R/display.R | 15 +++++++++++++++ tests/testthat/test_display_functions.r | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/R/display.R b/R/display.R index 9cf2571..3391113 100644 --- a/R/display.R +++ b/R/display.R @@ -59,6 +59,21 @@ display_raw <- function(mimetype, isbinary, data, file, metadata = NULL) { content <- prepare_content(isbinary, data, file) bundle <- list() bundle[[mimetype]] <- content + # Isolating full html pages (putting them in an iframe) + if (identical(mimetype, 'text/html')) { + if (grepl('', content, ignore.case = TRUE)) { + if (is.null(metadata)) { + metadata <- namedlist() + } + html_md <- metadata[[mimetype]] + if (is.null(html_md)) { + html_md <- list(isolated = TRUE) + } else { + html_md[['isolated']] <- TRUE + } + metadata[[mimetype]] <- html_md + } + } publish_mimebundle(bundle, metadata) } diff --git a/tests/testthat/test_display_functions.r b/tests/testthat/test_display_functions.r index 34e6683..3c5156e 100644 --- a/tests/testthat/test_display_functions.r +++ b/tests/testthat/test_display_functions.r @@ -69,6 +69,16 @@ test_that('display_html works', { expect_equal(get_last_data(), list(exp, NULL)) }) +test_that('display_html with full html page', { + exp <- namedlist() + exp_md <- namedlist() + display_html('text') + exp[['text/html']] <- 'text' + exp_md[['text/html']] <- list(isolated = TRUE) + expect_equal(get_last_data(),list(exp, exp_md)) +}) + + test_that('display_markdown works', { exp <- namedlist() display_markdown('data')