tstenner / luarefnos

Pure lua demo for Pandoc cross-references
BSD 2-Clause "Simplified" License
12 stars 3 forks source link

Fail with "nil value" when rendering tables without ID on pandoc 3.1.x #3

Closed dmitryperets closed 9 months ago

dmitryperets commented 9 months ago

On pandoc 3.1.11.1:

% pandoc --version
pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4

Trying to render a simple table without ID (the filter is not expected to do anything here):

% cat table.md 
 Revision        Date       Change Description
----------   ------------   --------------------
0.5           2022-07-05    Initial Draft

This results in failure:

% pandoc table.md --lua-filter refnos.lua -o table.html 
Error running filter refnos.lua:
refnos.lua:71: attempt to index a nil value (field 'integer index')
stack traceback:
    refnos.lua:247: in function <refnos.lua:244>

The problem seems to be here: https://github.com/tstenner/luarefnos/blob/4ae8fbca1d72c76481c975ab83649764c9557abb/refnos.lua#L245

I fixed it by replacing this line with:

if tbl.attr.identifier ~= "" then
tstenner commented 9 months ago

That fixes it, many thanks! I have added a test case and pushed the change.