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

pipe_tables seems to have broken syntax depending on the table size in input #9346

Closed
cderv opened this issue Jan 18, 2024 · 4 comments
Closed
Labels

Comments

@cderv
Copy link
Contributor

cderv commented Jan 18, 2024

Full context of how this was found at quarto-dev/quarto-cli#8332

For a long pipe tables like this (in file test.md for example)

|V1 |V2 |V3 |V4 |V5 |V6 |V7 |V8 |V9 |V10 |V11 |V12 |V13 |V14 |V15 |V16 |V17 |V18 |V19 |V20 |V21 |V22 |V23 |V24 |V25 |V26 |V27 |V28 |V29 |V30 |V31 |V32 |V33 |V34 |V35 |V36 |V37 |V38 |V39 |V40 |V41 |V42 |V43 |V44 |V45 |V46 |V47 |V48 |V49 |V50 |V51 |V52 |V53 |V54 |V55 |V56 |V57 |V58 |V59 |V60 |V61 |V62 |V63 |V64 |V65 |V66 |V67 |V68 |V69 |V70 |V71 |V72 |
|:--|:--|:--|:--|:--|:--|:--|:--|:--|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|:---|
|1  |2  |3  |4  |5  |6  |7  |8  |9  |10  |11  |12  |13  |14  |15  |16  |17  |18  |19  |20  |21  |22  |23  |24  |25  |26  |27  |28  |29  |30  |31  |32  |33  |34  |35  |36  |37  |38  |39  |40  |41  |42  |43  |44  |45  |46  |47  |48  |49  |50  |51  |52  |53  |54  |55  |56  |57  |58  |59  |60  |61  |62  |63  |64  |65  |66  |67  |68  |69  |70  |71  |72  |

It will produce a pipe table with no - and only :

$ pandoc -f markdown -t markdown_strict+pipe_tables test.md
| V1  | V2  | V3  | V4  | V5  | V6  | V7  | V8  | V9  | V10 | V11 | V12 | V13 | V14 | V15 | V16 | V17 | V18 | V19 | V20 | V21 | V22 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40 | V41 | V42 | V43 | V44 | V45 | V46 | V47 | V48 | V49 | V50 | V51 | V52 | V53 | V54 | V55 | V56 | V57 | V58 | V59 | V60 | V61 | V62 | V63 | V64 | V65 | V66 | V67 | V68 | V69 | V70 | V71 | V72 |
|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|
| 1   | 2   | 3   | 4   | 5   | 6   | 7   | 8   | 9   | 10  | 11  | 12  | 13  | 14  | 15  | 16  | 17  | 18  | 19  | 20  | 21  | 22  | 23  | 24  | 25  | 26  | 27  | 28  | 29  | 30  | 31  | 32  | 33  | 34  | 35  | 36  | 37  | 38  | 39  | 40  | 41  | 42  | 43  | 44  | 45  | 46  | 47  | 48  | 49  | 50  | 51  | 52  | 53  | 54  | 55  | 56  | 57  | 58  | 59  | 60  | 61  | 62  | 63  | 64  | 65  | 66  | 67  | 68  | 69  | 70  | 71  | 72  |

This seems to be broken syntax as even Pandoc can't read it as Table

$ pandoc -f markdown -t markdown_strict+pipe_tables test.md | pandoc -t native -f markdown_strict+pipe_tables | head -10
[ Para
    [ Str "|"
    , Space
    , Str "V1"
    , Space
    , Str "|"
    , Space
    , Str "V2"
    , Space
    , Str "|"

while the original can be read

$ pandoc -t native -f markdown_strict+pipe_tables test.md | head -10
[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )
    , ( AlignLeft , ColWidth 1.0752688172043e-2 )

This happens only after a certain number of column in the table. Removing only one in the above (71 instead of 72) produces some -

$ pandoc -f markdown -t markdown_strict+pipe_tables test.md
| V1  | V2  | V3  | V4  | V5  | V6  | V7  | V8  | V9  | V10 | V11 | V12 | V13 | V14 | V15 | V16 | V17 | V18 | V19 | V20 | V21 | V22 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40 | V41 | V42 | V43 | V44 | V45 | V46 | V47 | V48 | V49 | V50 | V51 | V52 | V53 | V54 | V55 | V56 | V57 | V58 | V59 | V60 | V61 | V62 | V63 | V64 | V65 | V66 | V67 | V68 | V69 | V70 | V71 |
|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|:-|
| 1   | 2   | 3   | 4   | 5   | 6   | 7   | 8   | 9   | 10  | 11  | 12  | 13  | 14  | 15  | 16  | 17  | 18  | 19  | 20  | 21  | 22  | 23  | 24  | 25  | 26  | 27  | 28  | 29  | 30  | 31  | 32  | 33  | 34  | 35  | 36  | 37  | 38  | 39  | 40  | 41  | 42  | 43  | 44  | 45  | 46  | 47  | 48  | 49  | 50  | 51  | 52  | 53  | 54  | 55  | 56  | 57  | 58  | 59  | 60  | 61  | 62  | 63  | 64  | 65  | 66  | 67  | 68  | 69  | 70  | 71  |

and it can be read

$ pandoc -f markdown -t markdown_strict+pipe_tables test.md | pandoc -t native -f markdown_strict+pipe_tables | head -10
[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )
    , ( AlignLeft , ColWidth 1.4084507042253521e-2 )

I did not found the pipe tables specs, but the syntax without the - works in some only markdown table previewer, but other tools like Pandoc does not recognize it as a table (docusaurus MDX in our case)

@cderv cderv added the bug label Jan 18, 2024
@jgm
Copy link
Owner

jgm commented Jan 18, 2024

@jgm
Copy link
Owner

jgm commented Jan 18, 2024

                          AlignLeft    -> ":" <> T.replicate (w + 1) "-"

For this to happen, one of the pipeWidths would have to be negative.

@jgm
Copy link
Owner

jgm commented Jan 18, 2024

So if colwidth is 72, and the number of columns is 72, then

                            (floor . (* fromIntegral (colwidth - (numcols +1))))

is negative. We can add code that ensures that this value is >= 1.

@jgm
Copy link
Owner

jgm commented Jan 18, 2024

A workaround for now would be to specify a larger value with --columns.

@jgm jgm closed this as completed in df1944f Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants