Skip to content

Commit e78a847

Browse files
committed
Add page-break option
1 parent 536873c commit e78a847

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

guide/src/format/config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Available configuration options for the `[output.html.print]` table:
224224

225225
- **enable:** Enable print support. When `false`, all print support will not be
226226
rendered. Defaults to `true`.
227+
- **page-break** Insert page breaks between chapters. Defaults to `true`.
227228

228229
Available configuration options for the `[output.html.fold]` table:
229230

@@ -292,6 +293,7 @@ input-404 = "not-found.md"
292293

293294
[output.html.print]
294295
enable = true
296+
page-break = true
295297

296298
[output.html.fold]
297299
enable = false

src/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,16 @@ impl HtmlConfig {
580580
pub struct Print {
581581
/// Whether print support is enabled.
582582
pub enable: bool,
583+
/// Insert page breaks between chapters. Default: `true`.
584+
pub page_break: bool,
583585
}
584586

585587
impl Default for Print {
586588
fn default() -> Self {
587-
Self { enable: true }
589+
Self {
590+
enable: true,
591+
page_break: true,
592+
}
588593
}
589594
}
590595

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ impl HtmlHandlebars {
4545
ctx.html_config.curly_quotes,
4646
Some(&path),
4747
);
48+
if !ctx.is_index && ctx.html_config.print.page_break {
49+
// Add page break between chapters
50+
// See https://developer.mozilla.org/en-US/docs/Web/CSS/break-before and https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-before
51+
// Add both two CSS properties because of the compatibility issue
52+
print_content.push_str(r#"<div id="chapter_begin" style="break-before: page; page-break-before: always;"></div>"#);
53+
}
4854
print_content.push_str(&fixed_content);
4955

5056
// Update the context with data for this file

0 commit comments

Comments
 (0)