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

Code example on https://pandoc.org/lua-filters.html#pandoc.simpletable appears to be wrong #6795

Closed
odkr opened this issue Nov 1, 2020 · 0 comments

Comments

@odkr
Copy link

odkr commented Nov 1, 2020

Description

There is a code example for using pandoc.SimpleTable on https://pandoc.org/lua-filters.html#pandoc.simpletable.

It reads:

local caption = "Overview"
local aligns = {pandoc.AlignDefault, pandoc.AlignDefault}
local widths = {0, 0} -- let pandoc determine col widths
local headers = {"Language", "Typing"}
local rows = {
  {{pandoc.Plain "Haskell"}, {pandoc.Plain "static"}},
  {{pandoc.Plain "Lua"}, {pandoc.Plain "Dynamic"}},
}
simple_table = pandoc.SimpleTable(
  caption,
  aligns,
  widths,
  headers,
  rows
)

However, this code throws error when run with Pandoc v2.11.0.4 on macOS v10.14.6.

Steps to reproduce

  1. Wrap the above code in a filter and save it as filter.lua

    function CodeBlock ()
        local caption = "Overview"
        local aligns = {pandoc.AlignDefault, pandoc.AlignDefault}
        local widths = {0, 0} -- let pandoc determine col widths
        local headers = {"Language", "Typing"}
        local rows = {
            {{pandoc.Plain "Haskell"}, {pandoc.Plain "static"}},
            {{pandoc.Plain "Lua"}, {pandoc.Plain "Dynamic"}},
        }
        simple_table = pandoc.SimpleTable(
            caption,
            aligns,
            widths,
            headers,
            rows
        )
        return pandoc.utils.from_simple_table(simple_table)
    end
  2. Call the filter with a document that runs it.

    pandoc -L filter.lua <<'EOF'
    > ```
    > ```
    > EOF

This throws:

Error running filter filter.lua:
PandocLuaError "Error during function call: Could not get SimpleTable: Could not read list: expected table, got 'Language' (string)"
stack traceback:
[C]: in function 'pandoc.utils.from_simple_table'
filter.lua:17: in function 'CodeBlock'

Getting the code to work

I got the code to work by changing

local headers = {"Language", "Typing"}

to

local headers = {{pandoc.Para({pandoc.Str "Language"})}, {pandoc.Para({pandoc.Str "Typing"})}}
@jgm jgm closed this as completed in ba4dfd4 Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant