From c7e601a218b612ac67ba1fa142138722614d7075 Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Thu, 20 Oct 2016 13:34:56 -0500 Subject: [PATCH] experiment to add `noquote` and `I()` for attributes useful in `JSX` --- R/tags.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/tags.R b/R/tags.R index 64814472..eff166cb 100644 --- a/R/tags.R +++ b/R/tags.R @@ -395,7 +395,13 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") { textWriter(paste8(indentText, "<", tag$name, sep="")) # Convert all attribs to chars explicitly; prevents us from messing up factors - attribs <- lapply(tag$attribs, as.character) + attribs <- lapply(tag$attribs, function(x){ + if(inherits(x, c("AsIs","noquote"))){ + x + } else { + as.character(x) + } + }) # concatenate attributes # split() is very slow, so avoid it if possible if (anyDuplicated(names(attribs))) @@ -404,12 +410,15 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") { # write attributes for (attrib in names(attribs)) { attribValue <- attribs[[attrib]] - if (!is.na(attribValue)) { + if (!is.na(attribValue) && !inherits(attribValue,c("AsIs","noquote"))) { if (is.logical(attribValue)) attribValue <- tolower(attribValue) text <- htmlEscape(attribValue, attribute=TRUE) textWriter(paste8(" ", attrib,"=\"", text, "\"", sep="")) } + else if(inherits(attribValue,c("AsIs","noquote"))){ + textWriter(paste8(" ", attrib, "=", attribValue, sep="") ) + } else { textWriter(paste8(" ", attrib, sep="")) }