summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-11-20 18:31:23 +0100
committerLaurenz <laurmaedje@gmail.com>2023-11-20 18:31:29 +0100
commitc1bc529986f723f8bb06feedfbdc98520763ceb9 (patch)
tree857eae7762d9d5a41b2f1351e4f6aadeb4160cd6 /crates
parentb5956ca3f123085ddd9c6b518443b6a85509ded6 (diff)
Support arbitrary content for document title
For PDF, they will be immediately turned into plain text. However, it's still useful because templates can now accept content titles (with math or such things) instead of forcing strings because of set document. Moreover, it will be useful with "get rules" in the future.
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/meta/document.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/typst-library/src/meta/document.rs b/crates/typst-library/src/meta/document.rs
index f6ff6812..581be60c 100644
--- a/crates/typst-library/src/meta/document.rs
+++ b/crates/typst-library/src/meta/document.rs
@@ -13,7 +13,7 @@ use crate::prelude::*;
/// rule must appear before any of the document's contents.
///
/// ```example
-/// #set document(title: "Hello")
+/// #set document(title: [Hello])
///
/// This has no visible output, but
/// embeds metadata into the PDF!
@@ -25,7 +25,10 @@ use crate::prelude::*;
pub struct DocumentElem {
/// The document's title. This is often rendered as the title of the
/// PDF viewer window.
- pub title: Option<EcoString>,
+ ///
+ /// While this can be arbitrary content, PDF viewers only support plain text
+ /// titles, so the conversion might be lossy.
+ pub title: Option<Content>,
/// The document's authors.
pub author: Author,
@@ -90,7 +93,7 @@ impl LayoutRoot for DocumentElem {
Ok(Document {
pages,
- title: self.title(styles),
+ title: self.title(styles).map(|content| content.plain_text()),
author: self.author(styles).0,
keywords: self.keywords(styles).0,
date: self.date(styles),