Skip to content

Commit

Permalink
add support for PDF generation of reveal.js presentations in chrome_p…
Browse files Browse the repository at this point in the history
…rint()
  • Loading branch information
RLesur committed Nov 27, 2019
1 parent 11cf8ab commit 4573ae4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pagedown
Type: Package
Title: Paginate the HTML Output of R Markdown with CSS for Print
Version: 0.6.1
Version: 0.6.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Romain", "Lesur", role = c("aut", "cph"), comment = c(ORCID = "0000-0002-0721-5595")),
Expand All @@ -21,7 +21,7 @@ Description: Use the paged media properties in CSS and the JavaScript
reports, papers, business cards, resumes, and posters.
Imports: rmarkdown (>= 1.16), bookdown (>= 0.8), htmltools, jsonlite, later (>= 1.0.0),
processx, servr (>= 0.13), httpuv, xfun, websocket
Suggests: promises, testit, xaringan, pdftools
Suggests: promises, testit, xaringan, pdftools, revealjs
License: MIT + file LICENSE
URL: https://github.com/rstudio/pagedown
BugReports: https://github.com/rstudio/pagedown/issues
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Added support for pagebreaks: in output formats which use **paged.js**, a pagebreak can be forced using the LaTeX commands `\newpage` and `\pagebreak` or using the CSS classes `page-break-before` and `page-break-after`.

- **reveal.js** presentations can be printed to PDF using `chrome_print()`.

# CHANGES IN pagedown VERSION 0.6

## MINOR CHANGES
Expand Down
30 changes: 27 additions & 3 deletions inst/resources/js/chrome_print.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
(() => {
{
let RevealReady = new Promise((resolve) => {
window.addEventListener(
'DOMContentLoaded',
() => {
if (window.Reveal) {
if (!window.location.search.match( /print-pdf/gi )) {
window.location.search = 'print-pdf';
return;
}
Reveal.addEventListener('ready', resolve);
if (Reveal.isReady()) resolve();
} else {
resolve();
}
},
{capture: true, once: true}
);
});

let HTMLWidgetsReady = new Promise((resolve) => {
window.addEventListener(
'DOMContentLoaded',
Expand Down Expand Up @@ -40,5 +59,10 @@
);
});

window.pagedownReady = Promise.all([MathJaxReady, HTMLWidgetsReady, document.fonts.ready]);
})();
window.pagedownReady = Promise.all([
RevealReady,
MathJaxReady,
HTMLWidgetsReady,
document.fonts.ready
]);
}
11 changes: 11 additions & 0 deletions tests/test-travis/test-chrome.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ assert('chrome_print() works with a local file path', {
assert('chrome_print() works with html_paged format', {
(is_pdf(print_pdf('test-chrome.Rmd')))
})

assert('chrome_print() works with reveal.js presentations', {
f = print_pdf('test-revealjs.Rmd')

(is_pdf(f))

(identical(pdftools::pdf_info(f)$pages, 5L))

first_page_text_content = pdftools::pdf_text('reveal.pdf')[1]
(identical(first_page_text_content, 'Test reveal.js'))
})
29 changes: 29 additions & 0 deletions tests/test-travis/test-revealjs.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "Test reveal.js"
output: revealjs::revealjs_presentation
---

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Code and Output

```{r}
summary(cars)
```

## Slide with Plot

```{r, echo=FALSE}
plot(cars)
```

0 comments on commit 4573ae4

Please sign in to comment.