pandoc-ext / list-table

Write tables as list of cells and rows.
MIT License
25 stars 2 forks source link

list-table.lua throws version-number error when called via --filter, but works with --lua-filter #10

Closed julianbarg closed 7 months ago

julianbarg commented 7 months ago

I did a bunch of trial and error, but this error message really threw me for a loop. Running

pandoc test.md -o test.pdf --filter ./list-table.lua

I get the error lua: /home/jules/.pandoc/lua_filters/list-table3.lua:8: pandoc version >=2.11 is required . (Needless to say, I am using a newer version.) The filter works as expected when calling it via:

pandoc test.md -o test.pdf --lua-filter ./list-table.lua

helpatbbf commented 7 months ago

--filter runs a program:

% pandoc --help | grep filter
  -F PROGRAM            --filter=PROGRAM                                      
  -L SCRIPTPATH         --lua-filter=SCRIPTPATH     

Is this the standard list-table.lua? If it was executable (it would presumably need a lua shebang line) I guess it would run standalone and perhaps you'd get this output, but when I try it I just get this:

% pandoc simple.md --filter ./list-table.lua 
Error running filter ./list-table.lua:
Could not find executable ./list-table.lua
wlupton commented 7 months ago

(Sorry, that was me logged in as the wrong user.)

julianbarg commented 7 months ago

I tried it as both an executable and non-executable. Yes, I got that error message, too, and so I ran chmod +x on the file to "advance" to the error message above.

wlupton commented 7 months ago

OK. Did you also add a shebang line? I'm guessing that you did something like this (I didn't know that this worked):

#!/usr/bin/env lua
-- lua filter for RST-like list-tables in Markdown.
-- Copyright (C) 2021 Martin Fischer, released under MIT license

if PANDOC_VERSION and PANDOC_VERSION.must_be_at_least then
    PANDOC_VERSION:must_be_at_least("2.11")
else
    error("pandoc version >=2.11 is required")
end
...

With this I get the same as you:

% pandoc simple.md --filter ./list-table.lua 
lua: ././list-table.lua:8: pandoc version >=2.11 is required
stack traceback:
    [C]: in function 'error'
    ././list-table.lua:8: in main chunk
    [C]: in ?
Error running filter ./list-table.lua:
Filter returned error status 1

This happens because the lua script is running as a standalone executable and isn't receiving any lua context from pandoc, so PANDOC_VERSION is nil, the if test fails, and you get the error message.

But the bottom line is that this was never going to work! Do you now see why? If not, I suggest re-reading the relevant section of the manual.

julianbarg commented 7 months ago

I see, that makes sense. The debugging experience was frustrating, but that seems to be on pandoc's side.