From e78a8471c71c7a7b3b4e4f5d6f1c4ddb8e47b3c0 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Fri, 12 Mar 2021 14:00:29 +0800 Subject: [PATCH 1/2] Add page-break option --- guide/src/format/config.md | 2 ++ src/config.rs | 7 ++++++- src/renderer/html_handlebars/hbs_renderer.rs | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/guide/src/format/config.md b/guide/src/format/config.md index d9c77e66..65d05d80 100644 --- a/guide/src/format/config.md +++ b/guide/src/format/config.md @@ -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 rendered. Defaults to `true`. +- **page-break** Insert page breaks between chapters. Defaults to `true`. Available configuration options for the `[output.html.fold]` table: @@ -292,6 +293,7 @@ input-404 = "not-found.md" [output.html.print] enable = true +page-break = true [output.html.fold] enable = false diff --git a/src/config.rs b/src/config.rs index be7dae62..d196cf99 100644 --- a/src/config.rs +++ b/src/config.rs @@ -580,11 +580,16 @@ impl HtmlConfig { pub struct Print { /// Whether print support is enabled. pub enable: bool, + /// Insert page breaks between chapters. Default: `true`. + pub page_break: bool, } impl Default for Print { fn default() -> Self { - Self { enable: true } + Self { + enable: true, + page_break: true, + } } } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 66572d04..575c0040 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -45,6 +45,12 @@ impl HtmlHandlebars { ctx.html_config.curly_quotes, 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#"
"#); + } print_content.push_str(&fixed_content); // Update the context with data for this file From 0eb23efd44c96d79c96161648a6c286dbc7424c1 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Tue, 16 Mar 2021 09:33:19 +0800 Subject: [PATCH 2/2] Make page-break not configurable --- guide/src/format/config.md | 2 -- src/config.rs | 7 +------ src/renderer/html_handlebars/hbs_renderer.rs | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/guide/src/format/config.md b/guide/src/format/config.md index 65d05d80..d9c77e66 100644 --- a/guide/src/format/config.md +++ b/guide/src/format/config.md @@ -224,7 +224,6 @@ Available configuration options for the `[output.html.print]` table: - **enable:** Enable print support. When `false`, all print support will not be rendered. Defaults to `true`. -- **page-break** Insert page breaks between chapters. Defaults to `true`. Available configuration options for the `[output.html.fold]` table: @@ -293,7 +292,6 @@ input-404 = "not-found.md" [output.html.print] enable = true -page-break = true [output.html.fold] enable = false diff --git a/src/config.rs b/src/config.rs index d196cf99..be7dae62 100644 --- a/src/config.rs +++ b/src/config.rs @@ -580,16 +580,11 @@ impl HtmlConfig { pub struct Print { /// Whether print support is enabled. pub enable: bool, - /// Insert page breaks between chapters. Default: `true`. - pub page_break: bool, } impl Default for Print { fn default() -> Self { - Self { - enable: true, - page_break: true, - } + Self { enable: true } } } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 575c0040..f417a014 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -45,7 +45,7 @@ impl HtmlHandlebars { ctx.html_config.curly_quotes, Some(&path), ); - if !ctx.is_index && ctx.html_config.print.page_break { + if !ctx.is_index { // 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