Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docError: Luafilter example refuses to compile #4459

Closed
HaoZeke opened this issue Mar 17, 2018 · 3 comments
Closed

docError: Luafilter example refuses to compile #4459

HaoZeke opened this issue Mar 17, 2018 · 3 comments

Comments

@HaoZeke
Copy link

HaoZeke commented Mar 17, 2018

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

# 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 source for 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

sysneofetch

@jgm
Copy link
Owner

jgm commented Mar 18, 2018

@tarleb, any ideas?

@HeirOfNorton
Copy link
Contributor

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.

@tarleb
Copy link
Collaborator

tarleb commented Mar 19, 2018

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?

@jgm jgm closed this as completed in f5b89b5 Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants