Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
rmarkdown 2.2
================================================================================

- Fixed a bug with encoding when rendering `html_notebook` containing HTML widgets (thanks, @cderv, #1799).

- TOC title can now be specified for `html_document` via the top-level option `toc-title` in the YAML frontmatter (thanks, @atusy, #1771).

- Floating TOC can now distinguish upper/lower-cases (thanks, @atusy, #1783).
Expand Down
12 changes: 4 additions & 8 deletions R/render_html.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
notebook_render_html_widget <- function(output) {

# TODO: add htmlUnpreserve function to htmlwidgets?
unpreserved <- substring(
output,
n_bytes("<!--html_preserve-->") + 1,
n_bytes(output) - n_bytes("<!--/html_preserve-->")
)
unpreserved <- htmltools::extractPreserveChunks(output)

meta <- base64_encode_object(attr(output, "knit_meta"))

before <- sprintf("\n<!-- rnb-htmlwidget-begin %s-->", meta)
after <- "<!-- rnb-htmlwidget-end -->\n"
pasted <- paste(before, unpreserved, after, sep = "\n")
pasted <- paste(before, unpreserved$value, after, sep = "\n")

annotated <- htmltools::htmlPreserve(pasted)
annotated <- htmltools::restorePreserveChunks(pasted,
unpreserved$chunks)
attributes(annotated) <- attributes(output)

return(annotated)
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-notebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,26 @@ test_that("a custom output_source can be used on render", {
parsed <- parse_html_notebook(output_file)

})

test_that("UFT8 character in html widget does not break notebook annotation", {
# from issue in https://github.com/rstudio/rmarkdown/issues/1762
skip_on_cran()
# simulate html widget code
html_dependency_dummy <- function() {
htmltools::htmlDependency(
name = "dummy",
version = "0.0.0",
src = "dummy_file",
script = "dummy.js")
}
utf8_strings <- enc2utf8("éà")
output <- htmltools::htmlPreserve(utf8_strings)
output <- knitr::asis_output(output, meta = html_dependency_dummy())
reg_res <- paste0(
"<!-- rnb-htmlwidget-begin .*-->\n",
utf8_strings,"\n",
"<!-- rnb-htmlwidget-end -->\n"
)
expect_match(notebook_render_html_widget(output),
reg_res)
})