Skip to content

Commit cf9f836

Browse files
committed
Factor out common widget creation
1 parent 7ff5460 commit cf9f836

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

R/view.R

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,12 @@ str_view <- function(string, pattern, match = NA) {
3737
paste0("<span class='match'>", str_sub(string[has_match], loc[has_match, , drop = FALSE]), "</span>")
3838

3939
string <- str_replace_na(string)
40-
bullets <- htmltools::HTML(str_c(
40+
bullets <- str_c(
4141
"<ul>\n",
4242
str_c(" <li>", string, "</li>", collapse = "\n"),
4343
"\n</ul>"
44-
))
45-
46-
htmlwidgets::createWidget("str_view", list(html = bullets),
47-
sizingPolicy = htmlwidgets::sizingPolicy(
48-
knitr.figure = FALSE,
49-
defaultHeight = "auto"
50-
),
51-
package = "stringr")
44+
)
45+
str_view_widget(bullets)
5246
}
5347

5448
#' @rdname str_view
@@ -75,16 +69,24 @@ str_view_all <- function(string, pattern, match = NA) {
7569
})
7670
string <- unlist(string_list)
7771

78-
bullets <- htmltools::HTML(str_c(
72+
bullets <- str_c(
7973
"<ul>\n",
8074
str_c(" <li>", string, "</li>", collapse = "\n"),
8175
"\n</ul>"
82-
))
76+
)
77+
str_view_widget(bullets)
78+
}
79+
80+
str_view_widget <- function(html) {
81+
size <- htmlwidgets::sizingPolicy(
82+
knitr.figure = FALSE,
83+
defaultHeight = "auto"
84+
)
8385

84-
htmlwidgets::createWidget("str_view", list(html = bullets),
85-
sizingPolicy = htmlwidgets::sizingPolicy(
86-
knitr.figure = FALSE,
87-
defaultHeight = "auto"
88-
),
89-
package = "stringr")
86+
htmlwidgets::createWidget(
87+
"str_view",
88+
list(html = htmltools::HTML(html)),
89+
sizingPolicy = size,
90+
package = "stringr"
91+
)
9092
}

0 commit comments

Comments
 (0)