rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print

Home Page:https://pagedown.rbind.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adapt to Pandoc 2.17 changes

cderv opened this issue · comments

There was a big change in Lua for Pandoc regarding how meta values are treated.
https://pandoc.org/releases.html#pandoc-2.17-2022-01-12

Elements of type MetaValue are no longer pushed as values which have .t and .tag properties. This was already true for MetaString and MetaBool values, which are still marshaled as Lua strings and booleans, respectively. Affected values:

MetaBlocks values are marshaled as a Blocks list;
MetaInlines values are marshaled as a Inlines list;
MetaList values are marshaled as a generic pandoc Lists.
MetaMap values are marshaled as plain tables and no longer given any metatable.

We probably need to adjust some of our filters like

Meta = function(meta)
---------------------------------------
-- Keywords --
---------------------------------------
-- Test if there is one keyword:
if not meta.keywords then error("At least one keyword must be supplied.") end
-- Store plain keywords:
local plainKeywords = {}
if meta.keywords.t == "MetaList" then
for i, v in ipairs(meta.keywords) do
plainKeywords[i] = pandoc.utils.stringify(v)
end
else
-- we have only one keyword
plainKeywords = {pandoc.utils.stringify(meta.keywords)}
end
meta["keywords-plain"] = plainKeywords
---------------------------------------
-- Author --
---------------------------------------
local author = meta.author
if author.t == "MetaInlines" then
meta.author = {data = author, rank = "1"}
else
for i, v in ipairs(author) do
meta.author[i] = {data = v, rank = tostring(i)}
end
end
----------------------------------------
-- Build DOI from volume and issue --
----------------------------------------
meta.doi = getDOI(meta.volume, meta.issue)
----------------------------------------
-- Fallback values for missing params --
----------------------------------------
if not meta.month then meta.month = "MMMMMM" end
if not meta.year then meta.year = "YYYY" end
if not meta.volume then meta.volume = "VV" end
if not meta.issue then meta.issue = "II" end
if not meta.submitdate then meta.submitdate = "yyyy-mm-dd" end
if not meta.acceptdate then meta.acceptdate = "yyyy-mm-dd" end
return meta

.t no more exist and type must be checked using

pandoc.utils.type(meta.keywords) == "List"

This will work only for Pandoc 2.17 so we need to adjust to use several syntax depending on the Pandoc version probably to not break existing code and not set a hard requirement on Pandoc 2.17

Note that no error is thrown (nothing in CI even following #267) so this will silently have side effect with the Lua filter not applying as it should

Seems like we don't need to test the type in fact. This would help the filter to work with any version of Pandoc

diff --git a/inst/resources/lua/jss.lua b/inst/resources/lua/jss.lua
index ee8f841..70791aa 100644
--- a/inst/resources/lua/jss.lua
+++ b/inst/resources/lua/jss.lua
@@ -56,13 +56,8 @@ Meta = function(meta)
   -- Store plain keywords:
   local plainKeywords = {}

-  if meta.keywords.t == "MetaList" then
-    for i, v in ipairs(meta.keywords) do
-      plainKeywords[i] = pandoc.utils.stringify(v)
-    end
-  else
-    -- we have only one keyword
-    plainKeywords = {pandoc.utils.stringify(meta.keywords)}
+  for i, v in ipairs(meta.keywords) do
+    plainKeywords[i] = pandoc.utils.stringify(v)
   end

   meta["keywords-plain"] = plainKeywords
@@ -72,12 +67,8 @@ Meta = function(meta)
   ---------------------------------------
   local author = meta.author

-  if author.t == "MetaInlines" then
-    meta.author = {data = author, rank = "1"}
-  else
-    for i, v in ipairs(author) do
-      meta.author[i] = {data = v, rank = tostring(i)}
-    end
+  for i, v in ipairs(author) do
+    meta.author[i] = {data = v, rank = tostring(i)}
   end

@RLesur how does it looks ?

I don't see where to check the difference between MetaInlines and MetaList effect. The template uses for loops which seems to account for the two type 🤔

Ok I found why

author: Yihui Xie

One author in YAML will trigger the error when using 2.17