diff --git a/R/tags.R b/R/tags.R
index 7dd49dea..ccf16637 100644
--- a/R/tags.R
+++ b/R/tags.R
@@ -259,7 +259,7 @@ format.html <- function(x, ...) {
}
normalizeText <- function(text) {
- if (!is.null(attr(text, "html", TRUE)))
+ if (inherits(text, "html"))
text
else
htmlEscape(text, attribute=FALSE)
@@ -1168,12 +1168,11 @@ resolveFunctionalDependencies <- function(dependencies) {
#' cat(as.character(el))
#'
#' @export
-HTML <- function(text, ..., .noWS = NULL) {
- htmlText <- c(text, as.character(dots_list(...)))
+HTML <- function(..., .noWS = NULL) {
+ htmlText <- as.character(dots_list(...))
htmlText <- paste8(htmlText, collapse=" ")
- attr(htmlText, "html") <- TRUE
attr(htmlText, "noWS") <- .noWS
- class(htmlText) <- c("html", "character")
+ class(htmlText) <- "html"
htmlText
}
diff --git a/tests/testthat/test-tags.r b/tests/testthat/test-tags.r
index 1be6481a..87637c0c 100644
--- a/tests/testthat/test-tags.r
+++ b/tests/testthat/test-tags.r
@@ -211,13 +211,17 @@ test_that("Adding child tags", {
expect_identical(t2a, t2)
- # tagSetChildren preserves attributes
- x <- tagSetChildren(div(), HTML("text"))
- expect_identical(attr(x$children[[1]], "html", TRUE), TRUE)
+ # tagSetChildren preserves classes and attributes
+ txt <- HTML("text")
+ attr(txt, "myattr") <- "foo"
+ x <- tagSetChildren(div(), txt)
+ expect_true(inherits(x$children[[1]], "html"))
+ expect_identical(attr(x$children[[1]], "myattr", TRUE), "foo")
# tagAppendChildren preserves attributes
- x <- tagAppendChildren(div(), HTML("text"))
- expect_identical(attr(x$children[[1]], "html", TRUE), TRUE)
+ x <- tagAppendChildren(div(), txt)
+ expect_true(inherits(x$children[[1]], "html"))
+ expect_identical(attr(x$children[[1]], "myattr", TRUE), "foo")
})
@@ -389,22 +393,25 @@ test_that("tag/s with invalid noWS fails fast", {
})
test_that("Attributes are preserved", {
- # HTML() adds an attribute to the data structure (note that this is
- # different from the 'attribs' field in the list)
- x <- HTML("