Proposal: syntax for table cell spanning
main-kun opened this issue · 0 comments
Introduction
The purpose of this proposal is to extend table syntax with support for column and row spans. Major inspiration for this proposal is doxygen markdown table syntax. The aim is to provide a simple and intuitive way to create complex tables with minimal syntax overhead.
Syntax
^
- placed as the only content within a table cell signifies an increase in rowspan for the cell above
>
- placed as the only content within a table cell signifies an increase in colspan for the cell to the left
Multiple spans can be added up.
#|
|| Text ||
|| ^ ||
|| ^ ||
|| ^ ||
#|
should produce a cell spanning 4 rows. Similarly, multiple >
cells in succession will produce a cell spanning n+1 columns, where n is the number of >
cells.
Whitespace is not significant, | ^ |
= |^|
and | > |
= |>|
.
It's possible to escape these characters, \>
and \^
render a normal table cell with corresponding characters.
Examples
Basic rowspan
Markdown input
#|
|| **Heading1** | **Heading2** ||
|| Text1 | Text2 ||
|| ^ | Text3||
|#
Rendered HTML
Heading1 | Heading2 |
---|---|
Text1 | Text2 |
Text3 |
Basic colspan
Markdown input
#|
|| **Heading1** | **Heading2** ||
|| Text1 | Text2 ||
|| Text3 |>||
|#
Rendered HTML
Heading1 | Heading2 |
---|---|
Text1 | Text2 |
Text3 |
Mixed colspan and rowspan
Markdown input
#|
|| **Heading1** | **Heading2** | **Heading3**||
|| Text1 | Text2 | Text3||
|| Text4 |>| Text5 ||
|| ^ |>| Text 6 ||
|| Text 7 | Text8 | Text9 ||
|#
Rendered HTML
Heading1 | Heading2 | Heading3 |
---|---|---|
Text1 | Text2 | Text3 |
Text4 | Text5 | |
Text6 | ||
Text7 | Text8 | Text9 |
Edge cases
Mismatched spans
If a rowspan does not have a corresponding colspan, it can result in broken table layout. For instance:
#|
|| **Heading1** | **Heading2** | **Heading3**||
|| Text1 | Text2 | Text 3||
|| Text4 |>| Text5 ||
|| ^ | Text7 | Text 8 ||
|| Text 9 | Text10 | Text11 ||
|#
This markdown can be interpreted as a broken table with an excess cell:
Heading1 | Heading2 | Heading3 |
---|---|---|
Text1 | Text2 | Text3 |
Text4 | Text5 | |
Text6 | Text7 | |
Text8 | Text9 | Text10 |
To avoid this issue we can let the user know that the spans need to match in such cases, or render the table as plaintext to indicate that the table syntax is broken.