-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<script> and <style> are correctly ignored from search content (#459)
- Loading branch information
Showing
7 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: distill | ||
Title: 'R Markdown' Format for Scientific and Technical Writing | ||
Version: 1.3.12 | ||
Version: 1.3.13 | ||
Authors@R: c( | ||
person("JJ", "Allaire", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-0174-9868")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
skip_if_pandoc_not_installed <- function() { | ||
skip_if_not(rmarkdown::pandoc_available("2.0"), "pandoc >= 2.0 not available") | ||
local_rmd_file <- function(..., .env = parent.frame()) { | ||
path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd") | ||
xfun::write_utf8(c(...), path) | ||
path | ||
} | ||
|
||
local_render <- function(input, ..., .env = parent.frame()) { | ||
skip_if_not_pandoc() | ||
output_file <- withr::local_tempfile(.local_envir = .env) | ||
rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...) | ||
} | ||
|
||
.render_and_read <- function(input, ...) { | ||
skip_if_not_pandoc() | ||
output_file <- withr::local_tempfile() | ||
res <- rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...) | ||
xfun::read_utf8(res) | ||
} | ||
|
||
# Use to test pandoc availability or version lower than | ||
skip_if_not_pandoc <- function(ver = "2.0") { | ||
if (!rmarkdown::pandoc_available(ver)) { | ||
msg <- if (is.null(ver)) { | ||
"Pandoc is not available" | ||
} else { | ||
sprintf("Version of Pandoc is lower than %s.", ver) | ||
} | ||
skip(msg) | ||
} | ||
} | ||
|
||
# Use to test version greater than | ||
skip_if_pandoc <- function(ver = "2.0") { | ||
if (rmarkdown::pandoc_available(ver)) { | ||
msg <- if (is.null(ver)) { | ||
"Pandoc is available" | ||
} else { | ||
sprintf("Version of Pandoc is greater than %s.", ver) | ||
} | ||
skip(msg) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
test_that("script and style are not included as `article_content`", { | ||
skip_on_cran() | ||
skip_if_not_pandoc() | ||
rmd <- local_rmd_file(c( | ||
"---", "title: test", "---", | ||
"Some content", "", | ||
"<script> console.log('test')</script>", "", | ||
"<style>h1 { color: red }</style>", "" | ||
)) | ||
html <- local_render(rmd, output_format = 'distill::distill_article') | ||
expect_identical(str_trim(article_contents(html)), "Some content") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
test_that("distill articles can be created", { | ||
skip_if_pandoc_not_installed() | ||
skip_if_not_pandoc() | ||
expect_s3_class(distill_article(), "rmarkdown_output_format") | ||
}) | ||
|