You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pandoc --lua-filter=meta-vars.lua occupations.md
Error running filter meta-vars.lua:
Could not read list: Could not get Inline value: Expected a string but got a nil
MWE
# Filter
$ echo -e "local vars = {}\nfunction get_vars (meta)\n for k, v in pairs(meta) do\n if v.t == 'MetaInlines' then\n vars[\"\$\" .. k .. \"\$\"] = v\n end\n end\nend\n\nfunction replace (el)\n if vars[el.text] then\n return pandoc.Span(vars[el.text])\n else\n return el\n end\nend\n\nreturn {{Meta = get_vars}, {Str = replace}}"| tee meta-vars.lua
# Input
$ echo -e "---\nname: Samuel Q. Smith\noccupation: Professor of Phrenology\n---\n\nName\n\n: \\\$name\\\$\n\nOccupation\n\n: \\\$occupation\\\$\n"| tee occupations.md
# Command & Output
$ pandoc -s -t native -f markdown occupations.md --lua-filter=meta-vars.lua
Error running filter meta-vars.lua:
Could not read list: Could not get Inline value: Expected a string but got a nil
System Details
$ pandoc --version
pandoc 2.1.2
Compiled with pandoc-types 1.17.3.1, texmath 0.10.1.1, skylighting 0.6
Default user data directory: /home/haozeke/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web: http://pandoc.org
This is free software; see the sourcefor copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
$ lua -v
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
The text was updated successfully, but these errors were encountered:
Playing around with it (since I'm planning a filter with similar functionality) I think the problem is in the ensureList function in pandoc.lua. The Span constructor uses this to make sure its input is either a single regular element (which has a tag) or a plain list of elements (which does not). This filter in the example passes a MetaInlines element, which looks like both. The Span gets a single child element, MetaInlines (which is not a valid child of Span, I believe) rather than the list of elements contained in the MetaInlines.
This could be fixed either by changing ensureList to check for Meta elements as a special case, or by changing the filter in the example to extract the list of elements from the MetaInlines to pass to the Span constructor rather than passing in the MetaInlines directly.
Sorry for the late reply, and thanks for the analysis, @HeirOfNorton. It seems spot-on. For now, we best just fix the documentation (the long term solution should be to re-think the whole argument normalization approach). Could you provide a pull request?
Bug Report
Description
Compiling an example from the docs causes the following:
pandoc --lua-filter=meta-vars.lua occupations.md Error running filter meta-vars.lua: Could not read list: Could not get Inline value: Expected a string but got a nil
MWE
System Details
The text was updated successfully, but these errors were encountered: