mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Soft pagebreak
This commit is contained in:
parent
2f33ad0e0a
commit
7163b4a6c5
@ -164,8 +164,9 @@ pub struct PagebreakNode;
|
|||||||
|
|
||||||
#[node]
|
#[node]
|
||||||
impl PagebreakNode {
|
impl PagebreakNode {
|
||||||
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
|
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
|
||||||
Ok(Content::Pagebreak)
|
let soft = args.named("soft")?.unwrap_or(false);
|
||||||
|
Ok(Content::Pagebreak(soft))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ pub enum Content {
|
|||||||
/// An item in an ordered list.
|
/// An item in an ordered list.
|
||||||
Enum(ListItem),
|
Enum(ListItem),
|
||||||
/// A page break.
|
/// A page break.
|
||||||
Pagebreak,
|
Pagebreak(bool),
|
||||||
/// A page node.
|
/// A page node.
|
||||||
Page(PageNode),
|
Page(PageNode),
|
||||||
/// A node that can be realized with styles.
|
/// A node that can be realized with styles.
|
||||||
@ -262,7 +262,7 @@ impl Debug for Content {
|
|||||||
f.write_str(". ")?;
|
f.write_str(". ")?;
|
||||||
item.body.fmt(f)
|
item.body.fmt(f)
|
||||||
}
|
}
|
||||||
Self::Pagebreak => f.pad("Pagebreak"),
|
Self::Pagebreak(soft) => write!(f, "Pagebreak({soft})"),
|
||||||
Self::Page(page) => page.fmt(f),
|
Self::Page(page) => page.fmt(f),
|
||||||
Self::Show(node) => {
|
Self::Show(node) => {
|
||||||
f.write_str("Show(")?;
|
f.write_str("Show(")?;
|
||||||
@ -463,8 +463,8 @@ impl<'a> Builder<'a> {
|
|||||||
staged: vec![],
|
staged: vec![],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Content::Pagebreak => {
|
Content::Pagebreak(soft) => {
|
||||||
self.finish_page(ctx, true, true, styles)?;
|
self.finish_page(ctx, !soft, !soft, styles)?;
|
||||||
}
|
}
|
||||||
Content::Page(page) => {
|
Content::Page(page) => {
|
||||||
self.finish_page(ctx, false, false, styles)?;
|
self.finish_page(ctx, false, false, styles)?;
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 8.4 KiB |
@ -2,18 +2,29 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
// Just a pagebreak.
|
// Just a pagebreak.
|
||||||
// Should result in two auto-sized pages.
|
// Should result in two pages.
|
||||||
#pagebreak()
|
#pagebreak()
|
||||||
|
|
||||||
---
|
---
|
||||||
// Pagebreak, empty with styles and then 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()
|
#pagebreak()
|
||||||
#set page(width: 2cm, fill: conifer)
|
#set page(width: 2cm, fill: conifer)
|
||||||
#pagebreak()
|
#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.
|
// 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: 80pt, height: 30pt)
|
||||||
[#set page(width: 60pt); First]
|
[#set page(width: 60pt); First]
|
||||||
#pagebreak()
|
#pagebreak()
|
||||||
@ -21,3 +32,14 @@
|
|||||||
Third
|
Third
|
||||||
#page(height: 20pt, fill: forest)[]
|
#page(height: 20pt, fill: forest)[]
|
||||||
Fif[#set page();th]
|
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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user