pandoc
pandoc copied to clipboard
`pandoc.scaffolding.Writer.Blocks(blocks)` results in error `table expected, got number`
Explain the problem.
Running the following file test.lua:
Writer = pandoc.scaffolding.Writer
Writer.Block.Para = function(para) return 'para' end
Writer.Blocks({pandoc.Para('asdf'), pandoc.Para('qwer')})
as follows:
pandoc lua test.lua
results in the following error:
Error running Lua:
table expected, got number
stack traceback:
test.lua:3: in main chunk
Based on what is written in the custom writer documentation, I think this should work -- but it is entirely possible that I missed something!
Pandoc version?
pandoc 3.6.4
Features: +server +lua
Scripting engine: Lua 5.4
Writer.Block.Para = function(para) return 'para' end
You're returning a string from a function that expects a block or a list of blocks. Could that be the problem?
The documentation states:
The render functions must return a string, a pandoc.layout Doc element, or a list of such elements.
Furthermore, if I remove that line from the script, the same error happens, so I don't think that's the issue.
You're right. I'm not sure what is going on here -- it may be that something in scaffolding has gotten broken. Have you tried earlier pandoc versions?
I haven't tried using older versions of pandoc yet -- I just discovered this while playing around with custom writers, but I don't actually have a use case for a custom writer at the moment, so getting to the bottom of this has not been a priority. I thought I'd open an issue though, so that it is captured at least. I'm happy to look into this further when I find the time.
I can confirm this bug. It seems that the scaffolding writer works correctly when called via the Writer function, but not when any of the individual element functions is called outside of that.
In addition, it seems that pandoc.scaffolding.Writer is invoking pandoc.scaffolding.Writer.Blocks without passing WriterOptions. Is this the correct behaviour? The docs don't mention WriterOptions, and the reference does not specify a signature for this function, but I am assuming WriterOptions are needed to render each block.