jgm/djot.lua

`djot-reader.lua` cannot process tables

Closed this issue · 3 comments

Hi.

djot-reader.lua is not able to process tables. (See output two paragraphs below.)

The problem seems to be exclusively in the djot-reader.lua's, given lua bin/main.lua properly renders the HTML of the table, as well as the AST representation of djot.lua is almost identical to the one of djot.net/playground (the TypeScript version).

$ pandoc --version
pandoc 3.1.2
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/user/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

$ GIT_PAGER=cat git log --oneline -- djot-reader.lua
c0109d4 Initial commit (split from jgm/djot)

$ GIT_PAGER=cat git log --oneline -1
5970f1c (HEAD -> main, tag: 0.2.1, origin/main, origin/HEAD) Bump to 0.2.1.

$ cat test.dj
| Header 1 | Header 2 |
|---|---|
| Row 1.1 | Row 1.2 |
| Row 2.1 | Row 2.2 |

$ pandoc -f djot-reader.lua -t html test.dj -o test.html
Error running Lua:
table expected, got nil
        while retrieving list
        while retrieving function argument align
        while retrieving arguments for function SimpleTable
stack traceback:
        djot-reader.lua:201: in function <djot-reader.lua:164>
        (...tail calls...)
        djot-reader.lua:98: in method 'render_children'
        djot-reader.lua:111: in function <djot-reader.lua:108>
        (...tail calls...)

$ lua bin/main.lua test.dj
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1.1</td>
<td>Row 1.2</td>
</tr>
<tr>
<td>Row 2.1</td>
<td>Row 2.2</td>
</tr>
</table>

I tried to quickly look in the origin of the problem (see djot-reader-logging.diff and pandoc-djot-reader-stderr.txt in djot-reader-bug-report.zip), and I have the impression the parameter (node) sent to Renderer:table is not proper.

That is the furthest I managed to go by myself given my limited knowledge on Lua, but let me know whether I can support you further.

As a final remark, I insist on djot.lua instead of djot.js because of limitations on my environment, and given djot.js is not binary-distributed (as Pandoc is), it is not an optional for me to use at my current environment.

Thanks in advance.


djot-reader-logging.diff and pandoc-djot-reader-stderr.txt were extract by the commands below:

$ git diff > djot-reader-logging.diff

$ pandoc --verbose -f djot-reader.lua -t html test.dj 1>/dev/null 2> pandoc-djot-reader-stderr.txt
jgm commented

I'm still getting incorrect HTML, but now correct native, so looking into a possible bug in HTML writer...

jgm commented

Reopening because I don't understand this issue. I'm now getting the following, correct looking, native output:

[ Table
    ( "" , [] , [] )
    (Caption
       Nothing [ Plain [ Str "My" , Space , Str "table" ] ])
    [ ( AlignDefault , ColWidthDefault ) ]
    (TableHead
       ( "" , [] , [] )
       [ Row
           ( "" , [] , [] )
           [ Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "Header" , Space , Str "1" ] ]
           , Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "Header" , Space , Str "2" ] ]
           ]
       ])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Row" , Space , Str "1.1" ] ]
            , Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Row" , Space , Str "1.2" ] ]
            ]
        , Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Row" , Space , Str "2.1" ] ]
            , Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Row" , Space , Str "2.2" ] ]
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

But when I render this to HTML or any other format, I only get 1.1 and 2.1 -- the second column is omitted! What is happening here?

jgm commented

Ah, it's because there's only one element in the colspecs.