Allow multiple authors

This commit is contained in:
Laurenz 2023-02-24 14:09:38 +01:00
parent 6547c2d6d5
commit 448844d66c
7 changed files with 33 additions and 16 deletions

View File

@ -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! {

View File

@ -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<_>>()?),
}

View File

@ -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()))
}

View File

@ -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.

View File

@ -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.

View File

@ -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();

View File

@ -5,6 +5,17 @@
#set document(title: "Hello")
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