Skip to content

Commit

Permalink
use the pagebreak feature provided by rmarkdown 1.16 (rstudio/rmarkdo…
Browse files Browse the repository at this point in the history
  • Loading branch information
RLesur committed Nov 15, 2019
1 parent fb3f770 commit d3b2100
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ cache: packages
pandoc_version: 2.3.1
addons:
chrome: stable
apt:
sources:
- sourceline: 'ppa:cran/poppler'
packages:
- libpoppler-cpp-dev

before_install:
- "curl https://xran.yihui.name/.gitconfig -o ~/.gitconfig"
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Description: Use the paged media properties in CSS and the JavaScript
pages. Each page can have its page size, page numbers, margin boxes, and
running headers, etc. Applications of this package include books, letters,
reports, papers, business cards, resumes, and posters.
Imports: rmarkdown (>= 1.14), bookdown (>= 0.8), htmltools, jsonlite, later (>= 1.0.0),
Imports: rmarkdown (>= 1.16), bookdown (>= 0.8), htmltools, jsonlite, later (>= 1.0.0),
processx, servr (>= 0.13), httpuv, xfun, websocket
Suggests: promises, testit, xaringan
Suggests: promises, testit, xaringan, pdftools
License: MIT + file LICENSE
URL: https://github.com/rstudio/pagedown
BugReports: https://github.com/rstudio/pagedown/issues
Expand Down
10 changes: 9 additions & 1 deletion R/paged.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ html_format = function(
css2 = grep('[.]css$', css, value = TRUE, invert = TRUE)
css = setdiff(css, css2)
check_css(css2)

pandoc_args = c(
.pandoc_args,
pandoc_args,
# use the pagebreak pandoc filter provided by rmarkdown 1.15:
if (isTRUE(.pagedjs)) pandoc_metadata_arg('newpage_html_class', 'page-break-after')
)

html_document2 = function(..., extra_dependencies = list()) {
bookdown::html_document2(..., extra_dependencies = c(
extra_dependencies, .dependencies,
Expand All @@ -157,7 +165,7 @@ html_format = function(
}
html_document2(
..., self_contained = self_contained, mathjax = mathjax, css = css,
template = template, pandoc_args = c(.pandoc_args, pandoc_args)
template = template, pandoc_args = pandoc_args
)
}

Expand Down
12 changes: 12 additions & 0 deletions inst/examples/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ You can modify the horizontal positioning and the font size of the lines numbers

Please note that this feature is sensitive to elements which break the vertical rythm of the text like inline maths.

## Page breaks

There are two ways to force a page break:

- with the `\newpage` $\LaTeX$ command (`\pagebreak` also works)

- using one of these two CSS classes: `page-break-before` or `page-break-after`\
For example, to force a page break before a given section, use:
```markdown
### New section {.page-break-before}
```

## MathJax

The following test comes from <http://www.cs.toronto.edu/~yujiali/test/mathjax.html>.
Expand Down
8 changes: 8 additions & 0 deletions inst/resources/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
insertCSS(text);
};

const insertPageBreaksCSS = () => {
insertCSS(`
.page-break-after {break-after: page;}
.page-break-before {break-before: page;}
`);
};

window.PagedConfig.before = async () => {
// Front and back covers support
let frontCover = document.querySelector('.front-cover');
Expand All @@ -34,6 +41,7 @@
if (backCover) document.body.append(backCover);
insertCSSForCover('front-cover');
insertCSSForCover('back-cover');
insertPageBreaksCSS();

if (beforePaged) await beforePaged();
};
Expand Down
10 changes: 10 additions & 0 deletions tests/test-travis.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# run tests on Travis (these tests depend on Chrome)

print_pdf = function(input) {
chrome_print(
input, tempfile(),
# use --no-sandbox with travis
# https://docs.travis-ci.com/user/chrome#sandboxing
extra_args = c('--disable-gpu', '--no-sandbox')
)
}

if (!is.na(Sys.getenv('CI', NA))) testit::test_pkg('pagedown', 'test-travis')
9 changes: 0 additions & 9 deletions tests/test-travis/test-chrome.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
library(testit)

print_pdf = function(input) {
chrome_print(
input, tempfile(),
# use --no-sandbox with travis
# https://docs.travis-ci.com/user/chrome#sandboxing
extra_args = c('--disable-gpu', '--no-sandbox')
)
}

is_pdf = function(file) {
identical(readBin(file, 'raw', 5L), charToRaw('%PDF-'))
}
Expand Down
6 changes: 6 additions & 0 deletions tests/test-travis/test-features.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library(testit)

assert('Page breaks work', {
f = print_pdf('test-page-breaks.Rmd')
(identical(pdftools::pdf_info(f)$pages, 5L))
})
21 changes: 21 additions & 0 deletions tests/test-travis/test-page-breaks.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: "Test page breaks"
output:
pagedown::html_paged:
self_contained: false
css: null
---

# First page

\newpage

# Second page

\pagebreak

# Third page {.page-break-after}

# Fourth page

# Fifth page {.page-break-before}

0 comments on commit d3b2100

Please sign in to comment.