Multiline Table not working
-
By default you can't do it. You'd need to either:
- create a plugin to add that functionality
- use alternative sanitization (install nodebb-plugin-sanitizehtml and disable html sanitization in markdown plugin).
The second way is much easier, but due to the html parser used it has its own problems (for example if you ever want to write that something is less than or equal something, you can't use
x<=y
, because it will think you started a html tag and will cut out your post until>
is found or until the end. It's not really fixable unless sanitize-html changes its parser to something like parse5... It can only be worked around manually by modifying the plugin).Markdown doesn't have a line break tag other than actual line ending, so because it's basing the parsing on line endings you can't have more than 1 line in a cell.
EDIT: Markdown actually has a line break - but since NodeBB treats soft line breaks as new lines and not spaces, it's not really useful here usually. However, ending a line with a \ and a single enter (or 2+ spaces, but a backslash is more visual) will create a hard line break.
Perhaps making it work without disrupting a table cell would actually be a good idea? It'll make them harder to write, as you'll have to do something like:| first line of fists cell\ second line of first cell | first line of second cell\ second line of second cell | first line of third cell |
But it's much better than nothing.
-
There actually might be a way to support it without changing markdown-it code (which won't happen, see here: https://github.com/markdown-it/markdown-it ) and without even creating a plugin for it.
In available options there is a settingbreaks
that is disabled by default, but when enabled should convert\n
inside paragraphs into<br>
while parsing, which would enable users to insert <br> into tables without working html...Oh, that's weird. It's actually enabled in NodeBB always - there is no setting to turn it off. Yet \n doesn't work as seen here. I think I'll create an issue in nodebb-plugin-markdown and investigate it, cause I don't think that's expected behavior? Is it sanitized at some point and turned back into \n, changed before markdown-it parses it, or what?
Edit: ah, nevermind. I misunderstood this option. It's why a single newline works as a line break here, and it's not about turning \n as written into a <br>...
\n
is just \n to markdown-it... -
Just so it isn't missed in an edit: I found a markdown-it plugin that would fix this
https://github.com/RedBug312/markdown-it-multimd-table
It expands markdown table syntax greatly, allowing cells to span multiple columns and rows, create multiline cells without html, and create headerless tables. It seems to be based on MultiMarkdown syntax for tables, so at least there is also some standard. -
Created an issue and a PR with working markdown-it-multimd-table now
The syntax really isn't too esoteric in my opinion:
- multiline - just add a slash at the end of a row and it will be merged with the next row.
So the table from the first post would look like this:
| Fruit | Price | Advantages | | :-------------- | :------------------ | :------------------- | | Bananana | first line | first line | \ | | second line | second line | | Bananana | first line | first line | \ | | second line | second line |
- if you want a cell to span multiple columns just end it with the amount of pipes equal to number of columns you want it to span. Essentially - create a totally empty cells without even a space inside.
For example:
| 2-column header || | :--------------------- | ----------------------:| | single column| single column | | two columns ||
- Rowspan is done by including ^^ in the cell below the one we want to span multiple rows. So for example:
| Fruit | Price | Advantages | | :-------------- | :------------------ | :------------------- | | Bananana | two rows | one row | | Bananana | ^^ | one row |
- headerless is self-explaining I think Just don't add any header and do everything the same way as it was done.
- multiline - just add a slash at the end of a row and it will be merged with the next row.