Skip to content

Commit d7150f7

Browse files
committed
Process Raw Author Metadata safely
In typecript, we ensure that authors that arrive at the filter have been transformed into an array. When we call this directly with document YAML, the authors may be a simple string, like: ``` author: Harley Malloc ``` We need to deal with this case as well.
1 parent 602b390 commit d7150f7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/resources/filters/common/authors.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,25 @@ local kAffiliationAliasedFields = {
140140
-- a simple incremental counter that can be used for things like note numbers
141141
local kNumber = "number"
142142

143-
function processAuthorMeta(meta, authorInput)
143+
function processAuthorMeta(meta)
144144
if not _quarto.format.isHtmlOutput() and not _quarto.format.isLatexOutput() and not _quarto.format.isIpynbOutput() and not _quarto.format.isDocxOutput() then
145145
return
146146
end
147147

148-
if authorInput == nil then
149-
authorInput = kAuthorInput
148+
-- prefer to render 'authors' if it is available
149+
local authorsRaw = meta[kAuthor]
150+
if meta[kAUthors] then
151+
authorsRaw = meta[kAuthors]
150152
end
151-
local authorsRaw = meta[authorInput]
153+
154+
-- authors should be a table of tables (e.g. it should be an array of inlines or tables)
155+
-- if it isn't, transform it into one
156+
if type(authorsRaw) == "table" then
157+
if (type(authorsRaw[1]) ~= "table") then
158+
authorsRaw = {authorsRaw}
159+
end
160+
end
161+
152162

153163
-- the normalized authors
154164
local authors = {}

src/resources/filters/quarto-post/book.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ function quartoBook()
1919
local template = el.attr.attributes['template']
2020

2121
-- process any author information
22-
local input = 'author'
23-
if renderedDoc.meta['authors'] then
24-
input = 'authors'
25-
end
26-
local processedMeta = processAuthorMeta(renderedDoc.meta, input)
22+
local processedMeta = processAuthorMeta(renderedDoc.meta)
2723

2824
-- read the title block template
2925
local renderedBlocks = compileTemplate(template, processedMeta)

0 commit comments

Comments
 (0)