Reputation: 2268
I got a pretty complex markdown table with plenty of columns.
I want to keep linter (in my case it's makdownlint
) happy and keep lines pretty and in 80 characters limits. But headers data is complex so my table looks like this
| fooooooooooooo | baaaaaaaaar | foooooooooooo | baaaaaaaaar | fooooooooooo |
|----------------|-------------|---------------|-------------|--------------|
|1|2|3|4|5|
We result of that table is that I need and looks ok on GitHub
I'm not sure this is a great idea, but is there any way to split table cells between line in source, but keep rendered data the same?
Something like this:
| fooooooooooooo |\
| baaaaaaaaar \
| foooooooooooo \
| baaaaaaaaar \
| fooooooooooo |
Upvotes: 6
Views: 3939
Reputation: 42497
In short: No.
GitHub's spec does not provide for breaking a row across lines. Of note is the description of rows:
Each row consists of cells containing arbitrary text, in which inlines are parsed, separated by pipes (
|
). A leading and trailing pipe is also recommended for clarity of reading, and if there’s otherwise parsing ambiguity. Spaces between pipes and cell content are trimmed. Block-level elements cannot be inserted in a table.
Of course, while that doesn't specifically support it, it also doesn't explicitly exclude breaking a row across multiple lines. However, notice that the syntax does not offer any way (outside of a line break) to define when one row ends and another row begins (unlike the header row, which requires a "deliminator row" to divide it from the body of the table). As you cannot define the division between rows, then the only way the parser can determine when one row ends and another begins is with a line break.
And then we have this issue:
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 other words, the parser can not count columns to determine if the next line is a continuation of the previous row or a new row.
Finally, elsewhere the spec states that:
A backslash at the end of the line is a hard line break:
There are some exceptions for specific types of content, but tables are not mentioned at all in the backslash escapes section of the spec and therefore do not fit any of those exceptions. Thus, using a backslash escape at the end of the line only reinforces the fact that the line ends a row, which is the opposite of your desired effect.
So, no, there is no way to wrap a table row across multiple lines.
For comparison consider MultiMarkdown, which had support for the same table syntax long before GitHub offered it. MultiMarkdown's documentation plainly states:
Cell content must be on one line only
This behavior matches PHP Markdown Extra, which first introduced the syntax. In fact, I'm not aware of any implementation of this specific table syntax which supports any way for one row to be defined on multiple lines.
Upvotes: 8