erusev / parsedown

Better Markdown Parser in PHP
https://parsedown.org
MIT License
14.74k stars 1.12k forks source link

Cannot split table cells into more than one row #691

Closed troccoli closed 5 years ago

troccoli commented 5 years ago

With a lot of columns it's difficult to see all of them if they are in one single line. Also, I'm using a blade template for my MD (I create markdown emails in Laravel) and I cannot use blade's directive.

I have discovered (and maybe this is not intended) that I can split the headers into more than one line, but not the content. For example, the following

| Header 1 |
Header 2 |
Header 3 |
| --- | --- | --- |
| Cell 1 | Cell 2 | Cell 3 |

Results in

Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3

But the follwing

| Header 1 |
Header 2 |
Header 3 |
| --- | --- | --- |
| Cell 1 |
Cell 2 |
Cell 3 |

Results in

Header 1 Header 2 Header 3
Cell 1
Cell 2
Cell 3
aidantwoods commented 5 years ago

One thing that might cause difficulty here is that in the GitHub flavoured markdown spec when fewer cells are written, the spec instructs the remaining ones to be filled in as empty placeholders:

The remainder of the table’s rows may vary in the number of cells. If there are a number of cells fewer than the number of cells in the header row, empty cells are inserted. If there are greater, the excess is ignored:

In the case of the header row, this is required to match the number of cells in the delimiter row (so provided the delimiter row must exist on only one line, you could sort of get away with the header spanning multiple since it has a clear ending—GitHub's parser in the comments seems to concur).

Interestingly the spec language uses the word "rows" in places where it should probably use "lines" since it never really actually says how a parser should distinguish rows from one another, and so I'm not sure that the spec is well defined here :)

One way of approaching multi-line rows while allowing the "fewer cells means fill remaining" rule would be to say that \ with no trailing whitespace could "escape" the newline (and thus prevent the row from ending), and so (with support for it) what you're going for could be achieved via something like:

| Header 1 |
Header 2 |
Header 3 |
| --- | --- | --- |
| Cell 1 |\
Cell 2 |\
Cell 3 |

Could try opening an issue in GitHub's spec repo about the language around how "rows" are formally defined, and then might be able to sneak in the escape character as an additional feature as part of that cleanup ;-)

https://github.com/github/cmark-gfm/issues

troccoli commented 5 years ago

What you're saying @aidantwoods is that since there can only be one header row (in the rendered table) and the number of headers must match the number of delimiters, then the headers can span into more than one line, as they all belong to one row. This is not the case for cells, because each line (in the MD) is in fact a table row, and if he number of cells doesn't match the number of headers (or delimiters) this is fine.

Once you put it like that it actually makes sense. I don't think any more this is a bug to be honest.