pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

`pandoc.scaffolding.Writer.Blocks(blocks)` results in error `table expected, got number`

Open rnwst opened this issue 7 months ago • 5 comments

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

rnwst avatar May 03 '25 13:05 rnwst

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?

jgm avatar May 03 '25 17:05 jgm

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.

rnwst avatar May 03 '25 19:05 rnwst

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?

jgm avatar May 06 '25 19:05 jgm

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.

rnwst avatar May 08 '25 13:05 rnwst

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.

tarleb avatar May 20 '25 09:05 tarleb

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.

foxyseta avatar Jun 17 '25 14:06 foxyseta