Skip to content

Commit

Permalink
Typst template: use content rather than string...
Browse files Browse the repository at this point in the history
...for title, author, date, email.

Fixes #9823 (escaped `\@` in rendered email).
Allows formatting in title, author, date, and email fields.
Since the PDF metadata requires a string, and typst only
converts the title to a string (not the authors), we use
a small function content-to-string to do this conversion.
Background: typst/typst#2196
  • Loading branch information
jgm committed May 30, 2024
1 parent 441ef31 commit 0e92d94
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
10 changes: 5 additions & 5 deletions data/templates/default.typst
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ $if(author)$
authors: (
$for(author)$
$if(author.name)$
( name: "$author.name$",
affiliation: "$author.affiliation$",
email: "$author.email$" ),
( name: [$author.name$],
affiliation: [$author.affiliation$],
email: [$author.email$] ),
$else$
( name: "$author$",
( name: [$author$],
affiliation: "",
email: "" ),
$endif$
Expand All @@ -46,7 +46,7 @@ $if(keywords)$
keywords: ($for(keywords)$$keyword$$sep$,$endfor$),
$endif$
$if(date)$
date: "$date$",
date: [$date$],
$endif$
$if(lang)$
lang: "$lang$",
Expand Down
13 changes: 12 additions & 1 deletion data/templates/template.typst
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#let content-to-string(content) = {
if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")

This comment has been minimized.

Copy link
@black-desk

black-desk May 30, 2024

Contributor

Should be content.children.map(content-to-string).join("")

@jgm

This comment has been minimized.

Copy link
@jgm

jgm May 31, 2024

Author Owner

yes. thanks.

} else if content.has("body") {
content-to-string(content.body)
} else if content == [ ] {
" "
}
}
#let conf(
title: none,
subtitle: none,
Expand All @@ -17,7 +28,7 @@
) = {
set document(
title: title,
author: authors.map(author => author.name),
author: authors.map(author => content-to-string(author.name)),
keywords: keywords,
)
set page(
Expand Down
19 changes: 15 additions & 4 deletions test/writer.typst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
stroke: none
)

#let content-to-string(content) = {
if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")

This comment has been minimized.

Copy link
@black-desk

black-desk May 30, 2024

Contributor

Same here.

} else if content.has("body") {
content-to-string(content.body)
} else if content == [ ] {
" "
}
}
#let conf(
title: none,
subtitle: none,
Expand All @@ -39,7 +50,7 @@
) = {
set document(
title: title,
author: authors.map(author => author.name),
author: authors.map(author => content-to-string(author.name)),
keywords: keywords,
)
set page(
Expand Down Expand Up @@ -101,14 +112,14 @@
#show: doc => conf(
title: [Pandoc Test Suite],
authors: (
( name: "John MacFarlane",
( name: [John MacFarlane],
affiliation: "",
email: "" ),
( name: "Anonymous",
( name: [Anonymous],
affiliation: "",
email: "" ),
),
date: "July 17, 2006",
date: [July 17, 2006],
cols: 1,
doc,
)
Expand Down

0 comments on commit 0e92d94

Please sign in to comment.