summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-24 14:09:38 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-24 14:09:38 +0100
commit448844d66cef5f4980d0575e783757264c962bb5 (patch)
treef280aaef927da2a30c18f13cc124c8eb77ad3abf
parent6547c2d6d5b25f44e52ac56698ed08ff6a5dbb3a (diff)
Allow multiple authors
-rw-r--r--library/src/layout/grid.rs5
-rw-r--r--library/src/meta/document.rs16
-rw-r--r--library/src/text/misc.rs2
-rw-r--r--library/src/text/mod.rs5
-rw-r--r--src/doc.rs2
-rw-r--r--src/export/pdf/mod.rs8
-rw-r--r--tests/typ/meta/document.typ11
7 files changed, 33 insertions, 16 deletions
diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs
index 626cb82d..d0df8794 100644
--- a/library/src/layout/grid.rs
+++ b/library/src/layout/grid.rs
@@ -151,10 +151,7 @@ castable! {
TrackSizings,
sizing: Sizing => Self(vec![sizing]),
count: NonZeroUsize => Self(vec![Sizing::Auto; count.get()]),
- values: Array => Self(values
- .into_iter()
- .filter_map(|v| v.cast().ok())
- .collect()),
+ values: Array => Self(values.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
}
castable! {
diff --git a/library/src/meta/document.rs b/library/src/meta/document.rs
index 32e944dc..1d349b89 100644
--- a/library/src/meta/document.rs
+++ b/library/src/meta/document.rs
@@ -25,9 +25,9 @@ impl DocumentNode {
#[property(referenced)]
pub const TITLE: Option<EcoString> = None;
- /// The document's author.
+ /// The document's authors.
#[property(referenced)]
- pub const AUTHOR: Option<EcoString> = None;
+ pub const AUTHOR: Author = Author(vec![]);
}
impl LayoutRoot for DocumentNode {
@@ -43,7 +43,7 @@ impl LayoutRoot for DocumentNode {
Ok(Document {
pages,
title: styles.get(Self::TITLE).clone(),
- author: styles.get(Self::AUTHOR).clone(),
+ author: styles.get(Self::AUTHOR).0.clone(),
})
}
}
@@ -54,3 +54,13 @@ impl Debug for DocumentNode {
self.0.fmt(f)
}
}
+
+/// A list of authors.
+#[derive(Debug, Clone, Hash)]
+pub struct Author(Vec<EcoString>);
+
+castable! {
+ Author,
+ v: EcoString => Self(vec![v]),
+ v: Array => Self(v.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
+}
diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs
index 43aea021..68d46d80 100644
--- a/library/src/text/misc.rs
+++ b/library/src/text/misc.rs
@@ -374,5 +374,5 @@ pub fn smallcaps(args: &mut Args) -> SourceResult<Value> {
#[func]
pub fn lorem(args: &mut Args) -> SourceResult<Value> {
let words: usize = args.expect("number of words")?;
- Ok(Value::Str(lipsum::lipsum(words).into()))
+ Ok(Value::Str(lipsum::lipsum(words).replace("--", "–").into()))
}
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 1ef32fa4..2c7cac04 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -548,10 +548,7 @@ pub struct FallbackList(pub Vec<FontFamily>);
castable! {
FallbackList,
family: FontFamily => Self(vec![family]),
- values: Array => Self(values
- .into_iter()
- .filter_map(|v| v.cast().ok())
- .collect()),
+ values: Array => Self(values.into_iter().map(|v| v.cast()).collect::<StrResult<_>>()?),
}
/// The size of text.
diff --git a/src/doc.rs b/src/doc.rs
index f4a4d968..55e2f467 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -25,7 +25,7 @@ pub struct Document {
/// The document's title.
pub title: Option<EcoString>,
/// The document's author.
- pub author: Option<EcoString>,
+ pub author: Vec<EcoString>,
}
/// A finished layout with elements at fixed positions.
diff --git a/src/export/pdf/mod.rs b/src/export/pdf/mod.rs
index 69fa805b..3813bad5 100644
--- a/src/export/pdf/mod.rs
+++ b/src/export/pdf/mod.rs
@@ -122,9 +122,11 @@ fn write_catalog(ctx: &mut PdfContext) {
info.title(TextStr(title));
xmp.title([(None, title.as_str())]);
}
- if let Some(author) = &ctx.document.author {
- info.author(TextStr(author));
- xmp.creator([(author.as_str())]);
+
+ let authors = &ctx.document.author;
+ if !authors.is_empty() {
+ info.author(TextStr(&authors.join(", ")));
+ xmp.creator(authors.iter().map(|s| s.as_str()));
}
info.creator(TextStr("Typst"));
info.finish();
diff --git a/tests/typ/meta/document.typ b/tests/typ/meta/document.typ
index e8d53650..f2c7a8bb 100644
--- a/tests/typ/meta/document.typ
+++ b/tests/typ/meta/document.typ
@@ -6,6 +6,17 @@
What's up?
---
+// This, too.
+// Ref: false
+#set document(author: ("A", "B"))
+
+---
+// This, too.
+// Error: 23-29 expected string, found integer
+#set document(author: (123,))
+What's up?
+
+---
Hello
// Error: 2-30 must appear before any content