mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Allow multiple authors
This commit is contained in:
parent
6547c2d6d5
commit
448844d66c
@ -151,10 +151,7 @@ castable! {
|
|||||||
TrackSizings,
|
TrackSizings,
|
||||||
sizing: Sizing => Self(vec![sizing]),
|
sizing: Sizing => Self(vec![sizing]),
|
||||||
count: NonZeroUsize => Self(vec![Sizing::Auto; count.get()]),
|
count: NonZeroUsize => Self(vec![Sizing::Auto; count.get()]),
|
||||||
values: Array => Self(values
|
values: Array => Self(values.into_iter().map(Value::cast).collect::<StrResult<_>>()?),
|
||||||
.into_iter()
|
|
||||||
.filter_map(|v| v.cast().ok())
|
|
||||||
.collect()),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
castable! {
|
castable! {
|
||||||
|
@ -25,9 +25,9 @@ impl DocumentNode {
|
|||||||
#[property(referenced)]
|
#[property(referenced)]
|
||||||
pub const TITLE: Option<EcoString> = None;
|
pub const TITLE: Option<EcoString> = None;
|
||||||
|
|
||||||
/// The document's author.
|
/// The document's authors.
|
||||||
#[property(referenced)]
|
#[property(referenced)]
|
||||||
pub const AUTHOR: Option<EcoString> = None;
|
pub const AUTHOR: Author = Author(vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutRoot for DocumentNode {
|
impl LayoutRoot for DocumentNode {
|
||||||
@ -43,7 +43,7 @@ impl LayoutRoot for DocumentNode {
|
|||||||
Ok(Document {
|
Ok(Document {
|
||||||
pages,
|
pages,
|
||||||
title: styles.get(Self::TITLE).clone(),
|
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)
|
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<_>>()?),
|
||||||
|
}
|
||||||
|
@ -374,5 +374,5 @@ pub fn smallcaps(args: &mut Args) -> SourceResult<Value> {
|
|||||||
#[func]
|
#[func]
|
||||||
pub fn lorem(args: &mut Args) -> SourceResult<Value> {
|
pub fn lorem(args: &mut Args) -> SourceResult<Value> {
|
||||||
let words: usize = args.expect("number of words")?;
|
let words: usize = args.expect("number of words")?;
|
||||||
Ok(Value::Str(lipsum::lipsum(words).into()))
|
Ok(Value::Str(lipsum::lipsum(words).replace("--", "–").into()))
|
||||||
}
|
}
|
||||||
|
@ -548,10 +548,7 @@ pub struct FallbackList(pub Vec<FontFamily>);
|
|||||||
castable! {
|
castable! {
|
||||||
FallbackList,
|
FallbackList,
|
||||||
family: FontFamily => Self(vec![family]),
|
family: FontFamily => Self(vec![family]),
|
||||||
values: Array => Self(values
|
values: Array => Self(values.into_iter().map(|v| v.cast()).collect::<StrResult<_>>()?),
|
||||||
.into_iter()
|
|
||||||
.filter_map(|v| v.cast().ok())
|
|
||||||
.collect()),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The size of text.
|
/// The size of text.
|
||||||
|
@ -25,7 +25,7 @@ pub struct Document {
|
|||||||
/// The document's title.
|
/// The document's title.
|
||||||
pub title: Option<EcoString>,
|
pub title: Option<EcoString>,
|
||||||
/// The document's author.
|
/// The document's author.
|
||||||
pub author: Option<EcoString>,
|
pub author: Vec<EcoString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A finished layout with elements at fixed positions.
|
/// A finished layout with elements at fixed positions.
|
||||||
|
@ -122,9 +122,11 @@ fn write_catalog(ctx: &mut PdfContext) {
|
|||||||
info.title(TextStr(title));
|
info.title(TextStr(title));
|
||||||
xmp.title([(None, title.as_str())]);
|
xmp.title([(None, title.as_str())]);
|
||||||
}
|
}
|
||||||
if let Some(author) = &ctx.document.author {
|
|
||||||
info.author(TextStr(author));
|
let authors = &ctx.document.author;
|
||||||
xmp.creator([(author.as_str())]);
|
if !authors.is_empty() {
|
||||||
|
info.author(TextStr(&authors.join(", ")));
|
||||||
|
xmp.creator(authors.iter().map(|s| s.as_str()));
|
||||||
}
|
}
|
||||||
info.creator(TextStr("Typst"));
|
info.creator(TextStr("Typst"));
|
||||||
info.finish();
|
info.finish();
|
||||||
|
@ -5,6 +5,17 @@
|
|||||||
#set document(title: "Hello")
|
#set document(title: "Hello")
|
||||||
What's up?
|
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
|
Hello
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user