Add page-break option
This commit is contained in:
parent
536873ca26
commit
e78a8471c7
|
@ -224,6 +224,7 @@ Available configuration options for the `[output.html.print]` table:
|
||||||
|
|
||||||
- **enable:** Enable print support. When `false`, all print support will not be
|
- **enable:** Enable print support. When `false`, all print support will not be
|
||||||
rendered. Defaults to `true`.
|
rendered. Defaults to `true`.
|
||||||
|
- **page-break** Insert page breaks between chapters. Defaults to `true`.
|
||||||
|
|
||||||
Available configuration options for the `[output.html.fold]` table:
|
Available configuration options for the `[output.html.fold]` table:
|
||||||
|
|
||||||
|
@ -292,6 +293,7 @@ input-404 = "not-found.md"
|
||||||
|
|
||||||
[output.html.print]
|
[output.html.print]
|
||||||
enable = true
|
enable = true
|
||||||
|
page-break = true
|
||||||
|
|
||||||
[output.html.fold]
|
[output.html.fold]
|
||||||
enable = false
|
enable = false
|
||||||
|
|
|
@ -580,11 +580,16 @@ impl HtmlConfig {
|
||||||
pub struct Print {
|
pub struct Print {
|
||||||
/// Whether print support is enabled.
|
/// Whether print support is enabled.
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
|
/// Insert page breaks between chapters. Default: `true`.
|
||||||
|
pub page_break: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Print {
|
impl Default for Print {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { enable: true }
|
Self {
|
||||||
|
enable: true,
|
||||||
|
page_break: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,12 @@ impl HtmlHandlebars {
|
||||||
ctx.html_config.curly_quotes,
|
ctx.html_config.curly_quotes,
|
||||||
Some(&path),
|
Some(&path),
|
||||||
);
|
);
|
||||||
|
if !ctx.is_index && ctx.html_config.print.page_break {
|
||||||
|
// Add page break between chapters
|
||||||
|
// 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
|
||||||
|
// Add both two CSS properties because of the compatibility issue
|
||||||
|
print_content.push_str(r#"<div id="chapter_begin" style="break-before: page; page-break-before: always;"></div>"#);
|
||||||
|
}
|
||||||
print_content.push_str(&fixed_content);
|
print_content.push_str(&fixed_content);
|
||||||
|
|
||||||
// Update the context with data for this file
|
// Update the context with data for this file
|
||||||
|
|
Loading…
Reference in New Issue