diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index 13583f098..38ba53e9b 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -164,8 +164,9 @@ pub struct PagebreakNode; #[node] impl PagebreakNode { - fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> { - Ok(Content::Pagebreak) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + let soft = args.named("soft")?.unwrap_or(false); + Ok(Content::Pagebreak(soft)) } } diff --git a/src/model/content.rs b/src/model/content.rs index 4077f6963..04d5fc5f7 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -63,7 +63,7 @@ pub enum Content { /// An item in an ordered list. Enum(ListItem), /// A page break. - Pagebreak, + Pagebreak(bool), /// A page node. Page(PageNode), /// A node that can be realized with styles. @@ -262,7 +262,7 @@ impl Debug for Content { f.write_str(". ")?; item.body.fmt(f) } - Self::Pagebreak => f.pad("Pagebreak"), + Self::Pagebreak(soft) => write!(f, "Pagebreak({soft})"), Self::Page(page) => page.fmt(f), Self::Show(node) => { f.write_str("Show(")?; @@ -463,8 +463,8 @@ impl<'a> Builder<'a> { staged: vec![], }); } - Content::Pagebreak => { - self.finish_page(ctx, true, true, styles)?; + Content::Pagebreak(soft) => { + self.finish_page(ctx, !soft, !soft, styles)?; } Content::Page(page) => { self.finish_page(ctx, false, false, styles)?; diff --git a/tests/ref/layout/pagebreak.png b/tests/ref/layout/pagebreak.png index 293e1b06b..741ed50fd 100644 Binary files a/tests/ref/layout/pagebreak.png and b/tests/ref/layout/pagebreak.png differ diff --git a/tests/typ/layout/pagebreak.typ b/tests/typ/layout/pagebreak.typ index 005ca2445..df3b04238 100644 --- a/tests/typ/layout/pagebreak.typ +++ b/tests/typ/layout/pagebreak.typ @@ -2,18 +2,29 @@ --- // Just a pagebreak. -// Should result in two auto-sized pages. +// Should result in two pages. #pagebreak() --- // Pagebreak, empty with styles and then pagebreak -// Should result in one auto-sized page and two conifer-colored A11 pages. +// Should result in one auto-sized page and two conifer-colored 2cm wide pages. #pagebreak() #set page(width: 2cm, fill: conifer) #pagebreak() +--- +// Two text bodies separated with and surrounded by soft pagebreaks. +// Should result in two aqua-colored pages. +#set page(fill: aqua) +#pagebreak(soft: true) +First +#pagebreak(soft: true) +Second +#pagebreak(soft: true) + --- // Test a combination of pagebreaks, styled pages and pages with bodies. +// Should result in three five pages, with the fourth one being forest-colored. #set page(width: 80pt, height: 30pt) [#set page(width: 60pt); First] #pagebreak() @@ -21,3 +32,14 @@ Third #page(height: 20pt, fill: forest)[] Fif[#set page();th] + +--- +// Test hard and soft pagebreak followed by page with body. +// Should result in three navy-colored pages. +#set page(fill: navy) +#set text(fill: white) +First +#pagebreak() +#page[Second] +#pagebreak(soft: true) +#page[Third]