From 79497943bb1c5164dce308ad0f9b5cdf0a028042 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Mon, 7 Nov 2022 21:33:39 -0500 Subject: [PATCH] Fix unintentional dropping of html dependencies (#747) * fix(exercise_result): Fix unintentional dropping of html dependencies * test(exercise_result): Add test for broken behavior --- R/exercise.R | 2 +- tests/testthat/test-exercise.R | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/R/exercise.R b/R/exercise.R index d79b174ec..41efb4cac 100644 --- a/R/exercise.R +++ b/R/exercise.R @@ -1137,7 +1137,7 @@ exercise_result <- function( feedback$html <- feedback_as_html(feedback) } - if (is.character(html_output) && any(nzchar(html_output))) { + if (!inherits(html_output, "html") && is.character(html_output) && any(nzchar(html_output))) { html_output <- htmltools::HTML(html_output) } else if (length(html_output) == 0) { html_output <- NULL diff --git a/tests/testthat/test-exercise.R b/tests/testthat/test-exercise.R index 655dd84cd..4aaa1d32c 100644 --- a/tests/testthat/test-exercise.R +++ b/tests/testthat/test-exercise.R @@ -501,6 +501,16 @@ test_that("exercise_result() turns length-0 html_output into NULL", { expect_null(exercise_result(html_output = list())$html_output) }) +test_that("exercise_result() doesn't drop html dependencies from `html_output`", { + html_output <- htmltools::attachDependencies( + htmltools::HTML("

A basic paragraph.

"), + clipboardjs_html_dependency() + ) + res <- exercise_result(html_output = html_output) + expect_equal(as.character(res$html_output), as.character(html_output)) + expect_equal(htmltools::htmlDependencies(res$html_output), list(clipboardjs_html_dependency())) +}) + test_that("exercise_result_as_html() creates html for learnr", { expect_null(exercise_result_as_html("nope")) expect_null(exercise_result_as_html(list()))