tufte/0000755000176200001440000000000015042227512011401 5ustar liggesuserstufte/tests/0000755000176200001440000000000015042223722012542 5ustar liggesuserstufte/tests/testthat/0000755000176200001440000000000015042227512014403 5ustar liggesuserstufte/tests/testthat/test-html.R0000644000176200001440000000445415041710233016452 0ustar liggesuserstest_that("add marginnote", { expect_snapshot(marginnote_html("text")) expect_snapshot(marginnote_html("text", "#")) }) expect_refs_margin <- function( moved = FALSE, options = NULL, ..., variant = NULL ) { rmd <- test_path("resources/margins_references.Rmd") out <- withr::local_tempfile(fileext = ".html") rmd_temp <- withr::local_tempfile(fileext = ".Rmd") xfun::write_utf8( knitr::knit_expand(rmd, linked = if (moved) "yes" else "no"), rmd_temp ) rmarkdown::pandoc_convert( basename(rmd_temp), "html4", "markdown", output = out, citeproc = TRUE, verbose = FALSE, wd = dirname(rmd_temp), options = c("--wrap", "preserve", options), ... ) x <- xfun::read_utf8(out) expect_snapshot(margin_references(x), variant = variant) } citeproc_variant <- function() { if (!rmarkdown::pandoc_available("2.11")) { "pandoc-citeproc" } else if (!rmarkdown::pandoc_available("2.14.1")) { # new citeproc creates links on author "new-citeproc-post-2.14.0.2" } else if (!rmarkdown::pandoc_available("3.1.8")) { # Pandoc 2.14.1 fixed that "new-citeproc-post-2.14.1" } else { "new-citeproc-post-3.1.8" } } pandoc_variant <- citeproc_variant() test_that("put references in margin when link-citations: yes", { skip_on_cran() skip_if_not_pandoc() expect_refs_margin(moved = TRUE, variant = pandoc_variant) expect_refs_margin(moved = FALSE, variant = pandoc_variant) }) test_that("put references in margin when link-citations: yes using csl", { skip_on_cran() # requires recent Pandoc skip_if_not_pandoc("2.11") skip_if_offline("zotero.org") expect_refs_margin( moved = TRUE, variant = pandoc_variant, c("--csl", "https://www.zotero.org/styles/apa-6th-edition") ) expect_refs_margin( moved = TRUE, variant = pandoc_variant, c("--csl", "https://www.zotero.org/styles/chicago-author-date-16th-edition") ) }) test_that("footnotes are correctly parsed", { skip_on_cran() skip_if_not_pandoc() pandoc_html <- local_pandoc_convert( "Here is some text^[This should be a sidenote].", to = "html4" ) expect_identical( parse_footnotes(pandoc_html), list(items = "This should be a sidenote", range = 2:7) ) }) tufte/tests/testthat/resources/0000755000176200001440000000000014757122121016417 5ustar liggesuserstufte/tests/testthat/resources/margins_references.Rmd0000644000176200001440000000224514757122121022727 0ustar liggesusers--- title: "Test margin references" link-citations: {{linked}} references: - author: - family: Xie given: Yihui id: R-knitr issued: year: 2020 note: R package version 1.30 title: "Knitr: A general-purpose package for dynamic report generation in r" title-short: Knitr type: book url: "https://yihui.org/knitr/" - author: - family: Xie given: Yihui id: R-knitr2 issued: year: 2020 note: R package version 1.29 title: "Knitr: A general-purpose package for dynamic report generation in r - duplicate" title-short: Knitr type: book url: "https://yihui.org/knitr/" - author: - family: Xie given: Yihui - family: Allaire given: J. J. - family: Grolemund given: Garrett id: rmarkdown2018 issued: year: 2018 note: ISBN 9781138359338 publisher: Chapman; Hall/CRC publisher-place: Boca Raton, Florida title: "R markdown: The definitive guide" title-short: R markdown type: book url: "https://bookdown.org/yihui/rmarkdown" output: tufte::tufte_html --- See [@R-knitr]. See @R-knitr2 See @R-knitr and @rmarkdown2018 See [@R-knitr] and [@rmarkdown2018] tufte/tests/testthat/helpers.R0000644000176200001440000000300415041657263016176 0ustar liggesusers# Use to test pandoc availability or version lower than skip_if_not_pandoc <- function(ver = NULL) { 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 = NULL) { 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) } } 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, ...) } local_pandoc_convert <- function( text, from = "markdown", options = NULL, ..., .env = parent.frame() ) { skip_if_not_pandoc() rmd <- local_rmd_file(text) out <- withr::local_tempfile(.local_envir = .env) rmarkdown::pandoc_convert( rmd, from = from, output = out, options = c("--wrap", "preserve", options), ... ) xfun::read_utf8(out) } .render_and_read <- function(input, ...) { skip_if_not_pandoc() res <- local_render(input, ...) xfun::read_utf8(res) } tufte/tests/testthat/_snaps/0000755000176200001440000000000015041662774015702 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-2.14.1/0000755000176200001440000000000015041663044021774 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-2.14.1/html.md0000644000176200001440000003403515041662677023302 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/." [8] "
" [9] "
" [10] "———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/." [11] "
" [12] "
" [13] "Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown." [14] "
" [15] "
" # put references in margin when link-citations: yes using csl Code margin_references(x) Output [1] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/).

" [2] "

See Xie (2020bXie, Y. (2020b). Knitr: A general-purpose package for dynamic report generation in r - duplicate. Retrieved from https://yihui.org/knitr/)

" [3] "

See Xie (2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and Xie, Allaire, & Grolemund (2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" [4] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and (Xie et al., 2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" --- Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" tufte/tests/testthat/_snaps/new-citeproc-post-3.1.8/0000755000176200001440000000000015041710026021711 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-3.1.8/html.md0000644000176200001440000003403515041710026023204 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/." [8] "
" [9] "
" [10] "———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/." [11] "
" [12] "
" [13] "Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown." [14] "
" [15] "
" # put references in margin when link-citations: yes using csl Code margin_references(x) Output [1] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/).

" [2] "

See Xie (2020bXie, Y. (2020b). Knitr: A general-purpose package for dynamic report generation in r - duplicate. Retrieved from https://yihui.org/knitr/)

" [3] "

See Xie (2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and Xie, Allaire, & Grolemund (2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" [4] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and (Xie et al., 2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" --- Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" tufte/tests/testthat/_snaps/html.md0000644000176200001440000000064215041710026017152 0ustar liggesusers# add marginnote Code marginnote_html("text") Output [1] "text" --- Code marginnote_html("text", "#") Output [1] "text" tufte/tests/testthat/_snaps/new-citeproc-post-2.14.0.2/0000755000176200001440000000000014757122121022132 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-2.14.0.2/html.md0000644000176200001440000003404515041662257023434 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/. and Xie, Allaire, and Grolemund (2018)Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/." [8] "
" [9] "
" [10] "———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/." [11] "
" [12] "
" [13] "Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown." [14] "
" [15] "
" # put references in margin when link-citations: yes using csl Code margin_references(x) Output [1] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/).

" [2] "

See Xie (2020b)Xie, Y. (2020b). Knitr: A general-purpose package for dynamic report generation in r - duplicate. Retrieved from https://yihui.org/knitr/

" [3] "

See Xie (2020a)Xie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/ and Xie, Allaire, & Grolemund (2018)Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown

" [4] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and (Xie, Allaire, & Grolemund, 2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" --- Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/. and Xie, Allaire, and Grolemund (2018)Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" tufte/tests/testthat/_snaps/pandoc-citeproc/0000755000176200001440000000000014757122121020742 5ustar liggesuserstufte/tests/testthat/_snaps/pandoc-citeproc/html.md0000644000176200001440000001240014757122121022225 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R..

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in R - Duplicate.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R. and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.)

" [4] "

See (Xie 2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R. and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "

Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R.

" [8] "
" [9] "
" [10] "

———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in R - Duplicate.

" [11] "
" [12] "
" [13] "

Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.

" [14] "
" [15] "
" tufte/tests/testthat.R0000644000176200001440000000007214757122121014527 0ustar liggesuserslibrary(testthat) library(tufte) test_check("tufte") tufte/MD50000644000176200001440000000543515042227512011720 0ustar liggesusers383841d78e8a3feff3b8e4c85854e88a *DESCRIPTION a9d51443d84d97a59028acbfdef9dc23 *NAMESPACE bfa43adfbbad3daed03560a2b68d176d *NEWS.md c4b40e13759ee99bbb561c596dbd8363 *R/handout.R af3e4790b1b50c456b9635d50d283d32 *R/html.R 1b54137d4ae82b40a266122de6d1201b *R/tufte-package.R d1ca95b15725281b2d27a94bc470b52b *R/utils.R ac852d158c5ee415d660b005fd413008 *README.md efc9f3dc4c715db8af90f57aa9b329f4 *inst/WORDLIST fae49c9fecd1db5ee18d02ad9f4e8874 *inst/rmarkdown/templates/tufte_ctex/skeleton/skeleton.Rmd 222048a11bc5c91d34373204518b5de4 *inst/rmarkdown/templates/tufte_ctex/template.yaml e2160f3183decce83f5af3518c47b119 *inst/rmarkdown/templates/tufte_handout/resources/tufte-handout.tex fc8331b11781b66cba88e5a56d27e019 *inst/rmarkdown/templates/tufte_html/resources/LICENSE 3bd1c910de64aab4ef9166f303576d4f *inst/rmarkdown/templates/tufte_html/resources/envisioned.css 5294d5d521aab523c8acd8ac96cfe4c0 *inst/rmarkdown/templates/tufte_html/resources/et-book/bold-line-figures.ttf d6175af437d22f14e7cf64c370adc879 *inst/rmarkdown/templates/tufte_html/resources/et-book/display-italic-old-style-figures.ttf d54d0bf6aa7fcf3279d8812acb322c06 *inst/rmarkdown/templates/tufte_html/resources/et-book/roman-line-figures.ttf 638c7cda0684c1644411d3849e61995f *inst/rmarkdown/templates/tufte_html/resources/et-book/roman-old-style-figures.ttf ec3ca614f98c2fd411ee29beb65479a4 *inst/rmarkdown/templates/tufte_html/resources/et-book/semi-bold-old-style-figures.ttf f406ebc309b141a772354c05579ecb87 *inst/rmarkdown/templates/tufte_html/resources/tufte-background.css 44f11eb78c10191d36197d47554a2284 *inst/rmarkdown/templates/tufte_html/resources/tufte-fonts.css 106eedb70445da5744f6f2cc1ba9aff1 *inst/rmarkdown/templates/tufte_html/resources/tufte-italics.css 0ecb8741f8e81db4a8518a7372ee00e4 *inst/rmarkdown/templates/tufte_html/resources/tufte.css 97a17459de2855f01039ae8a067a87c3 *inst/rmarkdown/templates/tufte_html/skeleton/skeleton.Rmd 5906bb06661b829d81a83a43aeecd286 *inst/rmarkdown/templates/tufte_html/template.yaml aec5bdcdaf50bba6d29001ae30b9c5b8 *man/tufte-package.Rd 421b324d1b3cc93716e59270bbb6f74e *man/tufte_handout.Rd 2f14464938dee4b867b8f7d3c74dbc0d *tests/testthat.R 732d050b0f22f5bc5bc0019046a8960d *tests/testthat/_snaps/html.md cc8dd862eb346919920659c043d989f8 *tests/testthat/_snaps/new-citeproc-post-2.14.0.2/html.md e2cf7ec862bc71e570156a1090969bd6 *tests/testthat/_snaps/new-citeproc-post-2.14.1/html.md 2e46d9c06b73835176b93d8caef16dfd *tests/testthat/_snaps/new-citeproc-post-3.1.8/html.md 242a7c48de2e0a6a33da900da87f481b *tests/testthat/_snaps/pandoc-citeproc/html.md 4c94947aeecf350b5dffbad896bdb731 *tests/testthat/helpers.R 8d01c1e52230949de2a6518f412f4227 *tests/testthat/resources/margins_references.Rmd 0bf9549cc0a49095da023a571f07bbbc *tests/testthat/test-html.R 34960bb321726e8f41dfb403cdd8142c *tools/copy-tufte-css.sh tufte/R/0000755000176200001440000000000014757122121011604 5ustar liggesuserstufte/R/utils.R0000644000176200001440000000632515041657263013104 0ustar liggesusers.onLoad <- function(lib, pkg) { # this engine will be overridden in tufte_html/tufte_handout formats knitr::knit_engines$set(marginfigure = function(options) { 'Placeholder (you should not see this)' }) } #' @details `newthought()` can be used in inline R expressions in R #' Markdown #' ```r #' `r newthought(Some text)` #' ``` #' and it works for both #' HTML (\samp{text}) and PDF #' (\samp{\\newthought{text}}) output. #' @param text A character string to be presented as a \dQuote{new thought} #' (using small caps), or a margin note, or a footer of a quote #' @rdname tufte_handout #' @export #' @examples newthought("In this section") newthought <- function(text) { if (is_html_output()) { sprintf('%s', text) } else if (is_latex_output()) { sprintf("\\newthought{%s}", text) } else { sprintf('%s', text) } } #' @details `margin_note()` can be used in inline R expressions to write a #' margin note (like a sidenote but not numbered). #' @param icon A character string to indicate there is a hidden margin note when #' the page width is too narrow (by default it is a circled plus sign) #' @rdname tufte_handout #' @importFrom knitr is_html_output is_latex_output #' @export margin_note <- function(text, icon = "⊕") { if (is_html_output()) { marginnote_html(sprintf('%s', text), icon) } else if (is_latex_output()) { sprintf("\\marginnote{%s}", text) } else { warning("marginnote() only works for HTML and LaTeX output", call. = FALSE) text } } #' @details `quote_footer()` formats text as the footer of a quote. It puts #' `text` in \samp{} for HTML output, and #' after \samp{\\hfill} for LaTeX output (to right-align text). #' @rdname tufte_handout #' @export quote_footer <- function(text) { if (is_html_output()) { sprintf("", text) } else if (is_latex_output()) { sprintf("\\hfill %s", text) } else { warning( "quote_footer() only works for HTML and LaTeX output", call. = FALSE ) text } } #' @details `sans_serif()` applies sans-serif fonts to `text`. #' @rdname tufte_handout #' @export sans_serif <- function(text) { if (is_html_output()) { sprintf('%s', text) } else if (is_latex_output()) { sprintf("\\textsf{%s}", text) } else { warning("sans_serif() only works for HTML and LaTeX output", call. = FALSE) text } } template_resources <- function(name, ...) { system.file( "rmarkdown", "templates", name, "resources", ..., package = "tufte" ) } gsub_fixed <- function(...) gsub(..., fixed = TRUE) pandoc2.0 <- function() rmarkdown::pandoc_available("2.0") # add --wrap=preserve to pandoc args for pandoc 2.0: # https://github.com/rstudio/bookdown/issues/504 # https://github.com/rstudio/tufte/issues/115 add_wrap_preserve <- function(args, pandoc2 = pandoc2.0) { if (pandoc2 && !length(grep("--wrap", args))) { c("--wrap", "preserve", args) } else { args } } tufte/R/html.R0000644000176200001440000002362415041657263012711 0ustar liggesusers#' @details `tufte_html()` provides the HTML format based on the Tufte CSS: #' . #' @param tufte_features A character vector of style features to enable: #' `fonts` stands for the `et-book` fonts in the `tufte-css` #' project, `background` means the lightyellow background color of the #' page, and `italics` means whether to use italics for the headers. You #' can enable a subset of these features, or just disable all of them by #' `NULL`. When this argument is not used and the `tufte_variant` #' argument is not `default`, no features are enabled. #' @param tufte_variant A variant of the Tufte style. Currently supported styles #' are `default` (from the `tufte-css` project), and #' `envisioned` (inspired by the project `Envisioned CSS` #' but essentially just #' sets the font family to `Roboto Condensed`, and changed the #' background/foreground colors). #' @param margin_references Whether to place citations in margin notes. #' @rdname tufte_handout #' @export tufte_html <- function( ..., tufte_features = c("fonts", "background", "italics"), tufte_variant = c("default", "envisioned"), margin_references = TRUE ) { tufte_variant <- match.arg(tufte_variant) if (missing(tufte_features) && tufte_variant != "default") { tufte_features <- character() } html_document2 <- function(..., extra_dependencies = list()) { rmarkdown::html_document( ..., extra_dependencies = c( extra_dependencies, tufte_html_dependency(tufte_features, tufte_variant) ) ) } format <- html_document2(theme = NULL, ...) pandoc2 <- pandoc2.0() # add --wrap=preserve to pandoc args for pandoc 2.0: format$pandoc$args <- add_wrap_preserve(format$pandoc$args, pandoc2) # when fig.margin = TRUE, set fig.beforecode = TRUE so plots are moved before # code blocks, and they can be top-aligned ohooks <- knitr::opts_hooks$set(fig.margin = function(options) { if (isTRUE(options$fig.margin)) { options$fig.beforecode <- TRUE } options }) # make sure the existing post processor is called first in our new processor post_processor <- format$post_processor format$post_processor <- function(metadata, input, output, clean, verbose) { if (is.function(post_processor)) { output <- post_processor(metadata, input, output, clean, verbose) } knitr::opts_hooks$restore(ohooks) x <- xfun::read_utf8(output) fn_label <- paste0(knitr::opts_knit$get("rmarkdown.pandoc.id_prefix"), "fn") footnotes <- parse_footnotes(x, fn_label) notes <- footnotes$items # replace footnotes with sidenotes for (i in seq_along(notes)) { num <- sprintf( '%d', fn_label, i, if (pandoc2) "footnote-ref" else "footnoteRef", fn_label, i, i ) con <- sprintf( paste0( '', '', '%d %s' ), i, i, i, i, notes[i] ) x <- gsub_fixed(num, con, x) } # remove footnotes at the bottom if (length(footnotes$range)) { x <- x[-footnotes$range] } # replace citations with margin notes if (margin_references) { x <- margin_references(x) } # place figure captions in margin notes x[x == '

'] <- '

' # move to the same line as ; the previous line should # start with ", x), grep("^$", x[i])) { j <- j + 1 x[i] <- paste0(x[i], x[i + j]) x[i + j] <- "" } } # place table captions in the margin r <- "^$" for (i in grep(r, x)) { # the previous line should be
(.+)
or
if (!grepl("^$", x[i - 1])) { next } cap <- gsub(r, "\\1", x[i]) x[i] <- x[i - 1] x[i - 1] <- paste0( "

", '', cap, "

" ) } # add an incremental number to the id of