Skip to content

Commit 395d104

Browse files
authored
Follow up to #29: prevent escaping of HTML inside message content strings (#34)
1 parent da73dff commit 395d104

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

R/chat.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ chat_ui <- function(
112112
tag_name <- "shiny-chat-message"
113113
}
114114

115-
ui <- with_current_theme({
116-
htmltools::renderTags(content)
117-
})
115+
# `content` is most likely a string, so avoid overhead in that case
116+
# (it's also important that we *don't escape HTML* here).
117+
if (is.character(content)) {
118+
ui <- list(html = paste(content, collapse = "\n"))
119+
} else {
120+
ui <- with_current_theme(htmltools::renderTags(content))
121+
}
118122

119123
tag(
120124
tag_name,

R/markdown-stream.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ output_markdown_stream <- function(
4848
width = "100%",
4949
height = "auto"
5050
) {
51-
52-
ui <- with_current_theme({
53-
htmltools::renderTags(content)
54-
})
51+
52+
# `content` is most likely a string, so avoid overhead in that case
53+
# (it's also important that we *don't escape HTML* here).
54+
if (is.character(content)) {
55+
ui <- list(html = paste(content, collapse="\n"))
56+
} else {
57+
ui <- with_current_theme(htmltools::renderTags(content))
58+
}
5559

5660
htmltools::tag(
5761
"shiny-markdown-stream",

0 commit comments

Comments
 (0)