summaryrefslogtreecommitdiff
path: root/library/src/layout/page.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-05-17 14:41:46 +0200
committerLaurenz <laurmaedje@gmail.com>2023-05-17 14:41:46 +0200
commit551ea99d05166b0be50792f767ddd38b996e32fa (patch)
treeec5e86a087e79e8c181c7d4b904216a775227e2d /library/src/layout/page.rs
parent46aace78ac4ac1c075b9b1670dbb7372df1a0a82 (diff)
Show default values in documentation
Fixes #169 Fixes #1102
Diffstat (limited to 'library/src/layout/page.rs')
-rw-r--r--library/src/layout/page.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index cb0ed7dc..cfddc446 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -26,9 +26,9 @@ use crate::prelude::*;
/// Category: layout
#[element]
pub struct PageElem {
- /// A standard paper size to set width and height. When this is not
- /// specified, Typst defaults to `{"a4"}` paper.
+ /// A standard paper size to set width and height.
#[external]
+ #[default(Paper::A4)]
pub paper: Paper,
/// The width of the page.
@@ -470,6 +470,8 @@ cast_to_value! {
/// Specification of a paper.
#[derive(Debug, Copy, Clone, Hash)]
pub struct Paper {
+ /// The name of the paper.
+ name: &'static str,
/// The width of the paper in millimeters.
width: Scalar,
/// The height of the paper in millimeters.
@@ -490,12 +492,13 @@ impl Paper {
/// Defines paper constants and a paper parsing implementation.
macro_rules! papers {
- ($(($var:ident: $width:expr, $height: expr, $pat:literal))*) => {
+ ($(($var:ident: $width:expr, $height: expr, $name:literal))*) => {
/// Predefined papers.
///
/// Each paper is parsable from its name in kebab-case.
impl Paper {
$(pub const $var: Self = Self {
+ name: $name,
width: Scalar($width),
height: Scalar($height),
};)*
@@ -506,7 +509,7 @@ macro_rules! papers {
fn from_str(name: &str) -> Result<Self, Self::Err> {
match name.to_lowercase().as_str() {
- $($pat => Ok(Self::$var),)*
+ $($name => Ok(Self::$var),)*
_ => Err("unknown paper size"),
}
}
@@ -516,9 +519,13 @@ macro_rules! papers {
Paper,
$(
/// Produces a paper of the respective size.
- $pat => Self::$var,
+ $name => Self::$var,
)*
}
+
+ cast_to_value! {
+ v: Paper => v.name.into()
+ }
};
}