mandolyte / mdtopdf

Markdown to PDF
MIT License
133 stars 32 forks source link

Panic when table has an empty heading cell #61

Open rahji opened 3 months ago

rahji commented 3 months ago

A table like this:

|       | head2 | head3 |
| ----- | ----- | ----- |
| 1     | 2     | 3     |

causes a panic. As far as I know, it's legal markdown to have an empty heading cell, but not sure. I've never had a problem rendering it in any other way or converting it to PDF with pandoc, vscode extensions, etc.

jessp01 commented 3 months ago

Hi @rahji ,

Please see https://github.com/gomarkdown/markdown/issues/207

I can suggest a workaround that will produce the desired result:

| \     | head2 | head3 |
| ----- | ----- | ----- |
| 1     | 2     | 3     |  

1.pdf

But the problem runs deeper since, with the current code, the width of a column is determined by the length of the string used as the header. This is a problem regardless of the empty header, for example, consider:

| head1 | head2                            | head3 |
|-----------|--------------------------------|-----------|
| 1111    | 222222277777772     | 3           | 

222222277777772 will be cut off; but it's an even bigger problem when the header is an empty string.

I didn't write the original implementation but I'll take a look into changing it so that the width of the column is determined based on the longest string value in any of the respective cells (rather than that of the header).

rahji commented 3 months ago

Thanks for the workaround. I think I was most concerned that it results in a panic with no real info about the cause. I kind of guessed my way into finding that this was the cause. 😬