redbug312 / markdown-it-multimd-table

Multimarkdown table syntax plugin for markdown-it markdown parser
MIT License
146 stars 37 forks source link

Alternative syntax for colspan to support prettier auto format (vscode) #25

Closed sabicalija closed 3 years ago

sabicalija commented 4 years ago

Would it be possible to add additional colspan syntax so that auto-formatting with prettier is supported out-of-the-box?

When I write following table:

| Header 1 | Header 2 ||
| -- | -- | -- |
| Stuff 1 | Stuff 2.1 | Stuff 2.2 |

prettier will format it to:

| Header 1 | Header 2  |           |
| -------- | --------- | --------- |
| Stuff 1  | Stuff 2.1 | Stuff 2.2 |

thereby removing the colspan. Would it be possible to support something like the following, to avoid this issue:

| Header 1 | Header 2 |>>|
| -- | -- | -- |
| Stuff 1 | Stuff 2.1 | Stuff 2.2 |

Prettier would format it to:

| Header 1 | Header 2  | >>        |
| -------- | --------- | --------- |
| Stuff 1  | Stuff 2.1 | Stuff 2.2 |

So, if the colspan syntax supports | >> | in addition to ||, one could continue using formatOnSave with prettier. Allowing to configure this feature and escaping arrows (\>) when needed, could solve possible conflicts.

redbug312 commented 4 years ago

Sorry for the extremely late reply. :sweat:

The patch is relatively easy, as the commit above. I'm just considering an appropriate option sets, since it looks inconsistent to have rowspan and colspanSyntax options.

One rational solution lefts {colspan: "", rowspan: undefined} as default. This changes behavior of rowspan and thus have to propogate until v5.0.0; Moreover, the colspan option must treat empty string as the special case, or regex comes in for the alternative syntax: \s*<<\s*.

One compromising solution lefts {rowspan: false, colspanSyntax: undefined, rowspanSyntax: undefined} as default. But it seems somewhat confusing and redundant, and colspan problem still exists.

I've noticed relevant discussion in CommonMark forum, but no conclusion drawn yet. I may left this branch unmerged until other Markdown derivatives proposed other solutions. :confused: